Lab Quiz 5 Study Guide Flashcards
Assign variables
y = 2
x = 4
etc
Assign multiple values to a variable
variable = c()
Inside add as many values separated by commas
Loading datasets
Environment, import dataset, choose dataset to load
or
data(dataset name) for stuff in the R dataset package
Subset a portion of data
Variable = subset(filename, dataset == “data”)
Take mean of data
mean(x)
mean(variable$data)
Second one for if you already made a variable to be more specific
How to make a plot
hist(x)
boxplot(x)
plot(x,y)
Make sure the inside of the parenthesis is dataset$data
For plot, you need to have two dataset$data, the first one being the x-axis
How to label axes in a plot
After dataset$data, add:
xlab = “<name>"
ylab = "<name>"
main = "<name>"
Separate everything with commas if you want to have these on a graph</name></name></name>
How to find slope and y-intercept for a plot
lm(y ~ x)
This is similar to the plot(,) except with lm instead of ‘plot’, ~ instead of a comma, and reverse the order of y and x. This will give you the slope and intercept of the trendline for the plot
How to make a trendline from slope and y-intercept
abline(intercept,slope)
Use the intercept and slope from lm(dataset$data ~ dataset$data)
Use dataset from RStudio
data(datasetname)