Write down 5 questions you have about this dataset
# Arguments are data.frame, then comma separated column names
my_cols <- select(df, col1, col2, col3)
# Arguments are data.frame, then comma separated boolean operators
my_rows <- filter(df, col1 > col2, col2 < col3, col4 == "hello")
# Arguments are data.frame, then comma separated sorting columns
sorted_df <- arrange(df, col1, desc(col2))
# Arguments are data.frame, then comma separated new columns
new_df <- mutate(df, combined = col1 + col2, diff = col1 - col2)
credit: Nathan Stephens, Rstudio
# Select storm and pressure columns from storms dataframe
storms <- select(storms, storm, pressure)
credit: Nathan Stephens, Rstudio
# Filter down storms to storms with name Ana or Alberto
storms <- filter(storms, storm %in% c('Ana', 'Alberto')
credit: Nathan Stephens, Rstudio
# Add ratio and inverse ratio columns
storms <- mutate(storms, ratio = pressure/wind, inverse = 1/ratio
credit: Nathan Stephens, Rstudio
# Arrange storms by wind
storms <- arrange(storms, wind)
# Create a vector of 100 employees ("Employee 1", "Employee 2")
employees <- paste('Employee', 1:100)
# Create a vector of 2014 salaries using the runif function
salaries_2014 <- runif(100, 40000, 50000)
# Create a vector of 2015 salaries that are typically higher 2014
salaries_2015 <- salaries_2014 + runif(100, -5000, 10000)
# Create a data.frame 'salaries' by combining these vectors
salaries <- data.frame(employees, salaries_2014, salaries_2015)
# Mutate to calculate raises
salaries <- mutate(salaries, raise = salaries_2015 > salaries_2014)
filter(salaries, raise==TRUE)
# What is the class of the vehicle with the best hwy mpg in 1996?
best_car_96 <- filter(vehicles,
year == 1996,
hwy == max(hwy[year == 1996])
)
class_name <- select(best_car_96, class)
# What is the class of the vehicle with the best hwy mpg in 1996?
class_name <- select(
filter(vehicles,
year == 1996,
hwy == max(hwy[year == 1996])
),
class
)
best_car_1996
credit: Nathan Stephens, Rstudio
# What is the class of the vehicle with the best hwy mpg in 1996?
best_car_96 <- filter(vehicles,
year == 1996,
hwy == max(hwy[year == 1996])
) %>%
select(class)
Pass the results in as the first argument to the next function