Question
1. Load the starwars dataset in the tidyverse package. Do this by loading up the package first, then typing dat < starwars (no quotes) to
1. Load the starwars dataset in the tidyverse package. Do this by loading up the package first, then typing dat< starwars (no quotes) to save it into your memory. This dataset contains information on all characters in the star wars universe. You can find additional details in the helpfile.
(a) Create a new column called mechanical that checks if the character is mechanical or not. That is, if the characters species is droid then mechanical is yes otherwise it is no. You can do this by applying the ifelse function. Something like: mutate(mechanical=ifelse(species==droid,yes,no)) would work.
(b) Create a new dataset that gives for each species: (i) the average height of all characters within that species, (ii) the number of characters of that species, (iii) the average mass of that species, and (iv) whether the species is mechanical or not. Then sort the dataset by species count so that more popular species come first.
(c) Create one single plot that gives, for each species, its average height by average mass. You will see that there is one outlier in the data that is throwing off the whole plot (which is it?) so remove it from the data and make the plot again. Set the color of each point to reflect whether the species is mechanical or not, set the size of each point to reflect the species count.
(d) Do males and females in the Star Wars universe differ in height? To answer this question first filter the original dataset to only contain characters that have a gender of female or male. What other factors might contribute to the difference? Make some plots to support your conclusion.
2. Load the diamonds dataset. Each observation is one diamond that was sold, and contains information on its characteristics and the selling price. You can read the helpfile for details. (a) First make a scatterplot of the carat vs the price. Set the color of the points to reflect the color, and the shape of the points to reflect the cut. What can you conclude from this plot? 1 (b) To better understand the relationship between price, carat, cut, and clarity, we can make facet plots. From the previous plot, add the following: +facet grid(colorcut). This will create additional facet plots for each combination of color and cut. What can you conclude from these plots? (c) Make the previous plot from (b), but first round the carat of each diamond up to the nearest integer (this can be done with the ceiling function, e.g. ceiling(0.2)=1), and plot the average price instead. For instance, the first point on the first panel would be the average price of all 1-carat diamonds (after rounding), for a certain cut and certain color.
3. 10. This exercise involves the Boston housing data set. (a) To begin, load in the Boston data set. The Boston data set is part of the MASS library in R. > library(MASS) Now the data set is contained in the object Boston. > Boston Read about the data set: > ?Boston How many rows are in this data set? How many columns? What do the rows and columns represent? (b) Make some pairwise scatterplots of the predictors (columns) in this data set. Describe your findings. (c) Are any of the predictors associated with per capita crime rate? If so, explain the relationship. (d) Do any of the suburbs of Boston appear to have particularly high crime rates? Tax rates? Pupil-teacher ratios? Comment on the range of each predictor. (e) How many of the suburbs in this data set bound the Charles river? (f) What is the median pupil-teacher ratio among the towns in this data set? (g) Which suburb of Boston has lowest median value of owneroccupied homes? What are the values of the other predictors for that suburb, and how do those values compare to the overall ranges for those predictors? Comment on your findings. (h) In this data set, how many of the suburbs average more than seven rooms per dwelling? More than eight rooms per dwelling? Comment on the suburbs that average more than eight rooms per dwelling.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started