Introduction to Statistics (MAT/SST 115.03 2008S)
We'll be learning a bit more of R in this exercise. In particular, we'll think about ways to create new columns in a data frame and revisit ways to select rows from a data frame.
You can read in the data for this exercise with
ICC = read.csv("/home/rebelsky/Stats115/Data/IceCreamCalories.csv")
You can see the first and last few lines of the data set with
As those lines suggest, there are six columns in the table
You may also note that there are a lot of
NA values at the
end of the table. That's because the different columns are of different
lengths, but R likes to pad them into uniform lengths.
Recall that you can get a five-number summary using the
summary(ICC$BJcal) summary(ICC$CScal) summary(ICC$Dcal)
It is also possible to get all the summaries at once by just asking for a summary of the frame.
As you might hope, you make box plots in R with the
boxplot command. You make the
simplest box plots from vectors.
Suprisingly, R likes to make vertical box plots, rather than the
horizontal box plots that most of us like. To make R make horizontal
boxplots, you add
horizontal=T to the command.
Of course, we often like to stack box plots on top of each other to compare variables (as this problem requests). If the variables are already in a frame, we can just use those columns of the frame.
This exercise asks you to create a new column in the table. You can
create a new column in a table by referring to it. If the column is
based on other columns, you use the appropriate formula to compute it.
For example, suppose we call the new column
ICC$CScal2 = ICC$CScal / 170 * 146 / 2
Recall that we made a box plot from columns 2, 4, and 6 of the frame with
For the new box plot, you want columns 2, 7, and 6. (Or, if you want to keep the old data, 2, 4, 7, and 6.)
Copyright (c) 2007-8 Samuel A. Rebelsky.
This work is licensed under a Creative Commons
Attribution-NonCommercial 2.5 License. To view a copy of this
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.