Summary of R Commands For Statistics 100
Summary of R Commands For Statistics 100
The following is a summary of R commands we will be using throughout Statistics 100, and maybe
a few extras we will not end up using. Please refer to the homework and course notes for examples
of their usage, including the appropriate arguments of the commands. In the descriptions below,
fnc is an arbitrary R command.
y = fnc(x) − assigns the results of the function fnc evaluated at x to the variable y.
View(x) − view data frame x within R. Can also just type the name of the data frame at the
prompt.
Descriptive statistics:
table(x) − for categorical variable x, creates vector of counts of each unique category.
by(y,x,fnc) − with categorical x and function fnc, carry out fnc(y) for each level of x.
1
Graphics:
abline(model.fit) − add a regression line based on the model model.fit to an existing plot.
qnorm(p, mean, sd) − the value of x in p = P(X < x), where X ∼ N(mean, sd)
sample(n, size) − a random sample of size values from among the first n positive integers.
2
Statistical inference:
t.test(x, mu) − one-sample t-test or confidence interval with data in x, with null hypothesized
value mu.
t.test(x1, x2) − two-sample t-test or confidence interval for difference in means with data in
x1 and x2
mcnemar.test(x) − McNemar’s test for difference in Binomial probabilities with paired data,
with x containing 2 × 2 data frame.
step(model.fit) − stepwise variable selection for least-squares or logistic regressions, with largest
model in model.fit.