Importing a CSV file
data <- read.csv("file.csv")
Use when
Use when loading a spreadsheet-style data file into RStudio.
Output means
Creates a data frame called data.
Example
survey <- read.csv("survey.csv")
Higher Applications of Mathematics
Quick reference cards for common RStudio commands, when to use them, and how to interpret the output.
data <- read.csv("file.csv")
Use when loading a spreadsheet-style data file into RStudio.
Creates a data frame called data.
survey <- read.csv("survey.csv")
names(data)
Use after importing data to check exact variable names.
Lists the column names you can use in commands.
names(survey)
mean(x), median(x), sd(x), summary(x)
Use to describe centre, spread and range.
Gives numerical summaries for a variable.
mean(survey$height)
boxplot(x)
Use to compare spread, median and possible outliers.
Shows median, quartiles, range and outliers.
boxplot(survey$travel_time)
hist(x)
Use to show the shape of a numerical distribution.
Shows frequencies in grouped intervals.
hist(survey$screen_time)
plot(x, y)
Use to show the relationship between two numerical variables.
Each point represents one pair of values.
plot(survey$revision, survey$score)
cor(x, y)
Use to measure strength and direction of a linear relationship.
Returns a value between -1 and 1.
cor(survey$revision, survey$score)
model <- lm(y ~ x, data = data)
Use to fit a straight-line model and make predictions.
Gives intercept, gradient and model summary.
lm(score ~ revision, data = survey)
t.test(x)$conf.int
Use to estimate a population mean from sample data.
Gives a plausible interval for the true mean.
t.test(survey$height)$conf.int
t.test(x, mu = value)
Use to test whether a sample mean differs from a claimed mean.
Use the p-value to judge evidence against the claim.
t.test(times, mu = 30)
t.test(before, after, paired = TRUE)
Use when the same people are measured twice.
Tests whether the mean paired difference is 0.
t.test(before, after, paired = TRUE)
prop.test(c(success1, success2), c(total1, total2))
Use to compare two sample proportions.
Gives a p-value for evidence of a difference in proportions.
prop.test(c(42, 55), c(100, 120))
write.csv(results, "results.csv")
Use when saving a table for a project write-up.
Creates a CSV file from an R object.
write.csv(summary_table, "summary.csv")
Check spelling, capitals, brackets and data names
Use when R says an object is not found or a command fails.
Most early errors come from mistyped names or missing brackets.
survey$Height is different from survey$height.