Information Technology Reference
In-Depth Information
The solutions just described are similar to those for Recipe 1.10 , where we selected
columns by position. The only difference is that here we use column names instead of
column numbers. All the observations made in Recipe 1.10 apply here:
dfrm[["name"]] returns one column, not a data frame.
dfrm[c(" name 1 ", " name 2 ", ..., " name k ")] returns a data frame, not a column.
dfrm["name"] is a special case of the previous expression and so returns a data frame,
not a column.
• The matrix-style subscripting can return either a column or a data frame, so be
careful how many names you supply. See Recipe 1.10 for a discussion of this
“gotcha” and using drop=FALSE .
There is one new addition:
dfrm$name
This is identical in effect to dfrm[["name"]] , but it's easier to type and to read.
See Also
See Recipe 1.10 to understand more about selecting columns.
1.12 Forming a Confidence Interval for a Mean
Problem
You have a sample from a population. Given that sample, you want to determine a
confidence interval for the population's mean.
Solution
Apply the t.test function to your sample x :
> t.test(x)
The output includes a confidence interval at the 95% confidence level. To see intervals
at other levels, use the conf.level argument.
If your sample size n is small, the underlying population must be normally distributed
for there to be a meaningful confidence interval. A good rule of thumb is that “small”
means n < 30.
Discussion
Applying the t.test function to a vector yields a lot of output. Buried in the output is
a confidence interval:
 
Search WWH ::




Custom Search