RStudio Command Reference Guide
Anything in blue is information that you give the computer, such as a set_name that you make up for an
original dataset or the name of an uploaded dataset, or a var_name, which is the name of the variable
from a specific dataset that you need to use. Anything in red is just an example number to represent
what you might input if you were making your own dataset.
Cat_var_name is the name of a categorical variable, while quant_var_name is the name of a quantitative
variable. If you see something like x_var or y_var, those are the names of the variables that you want on
the x and y axes respectively.
Basics:
Entering a new dataset— set_name=c(16,14,13,13,14)
Graphs:
Histograms— hist(quant_var_name)
Boxplots— boxplot(quant_var_name)
Side-by-Side Boxplots— boxplot(y_var_name ~ x_var_name)
Bar Chart— barchart(cat_var_name)
Scatterplot— plot(y_var_name ~ x_var_name)
Numerical Descriptive Stats For One or Two Quantitative Variables:
Mean— mean(quant_var_name)
Median— median(quant_var_name)
Range— range(quant_var_name)
Five Number Summary— fivenum(quant_var_name)
Standard Deviation— sd(quant_var_name)
Tally— tally(cat_var_name)
Percentile— quantile(quant_var_name, 0.1)
Correlation Coefficient— cor(y_var_name ~ x_var_name)
cor(y_var_name, x_var_name)
Linear Model— model_name=lm(y_var_name ~ x_var_name)
Abline— abline(model_name)
Numerical Descriptive Stats For One Quantitative Variable and One Categorical Variable:
Mean— mean(quant_var_name ~ cat_var_name)
Median— median(quant_var_name ~ cat_var_name)
Range— range(quant_var_name ~ cat_var_name)
Five Number Summary— fivenum(quant_var_name[cat_var_name == “Name of Sub-category”])
Standard Deviation— sd(quant_var_name ~ cat_var_name)
Probability with a Normal Distribution
Probability— pnorm(cutoff-value, mean = 45, sd = 5)
pnorm calculates the area to the left of the cutoff value
Cut-off Value— qnorm(area, mean = 45, sd = 5)
qnorm calculates the cutoff value, where the area to the left is
equal to the input area