Aug 3, 2024
5 + 7, abs(-17)x <- -12, y <- c(-12, 6, 0, -1)<- for assignment (preferred over =)x + 7, abs(x), y * 2, abs(y)*read_excel functionView() to see the imported datalibrary(readxl) to import Excel datareadxl package using install.packages('readxl')Scooby <- read_excel('file_path')mean(Scooby$runtime)mean(Scooby$imdb, na.rm = TRUE)File -> New File -> R Scriptcmd + Enter (Mac) or ctrl + Enter (PC)library(tidyverse)data()View(mpg), ?mpg, glimpse(mpg)filter function
filter(mpg, cty >= 20)mpg_efficient <- filter(mpg, cty >= 20)mutate
mpg_metric <- mutate(mpg, cty_metric = cty * conversion_factor)%>% to chain commands
mpg %>% filter(cty >= 20) %>% mutate(cty_metric = cty * conversion_factor)group_by and summarize with summarize
mpg %>% group_by(class) %>% summarize(mean_cty = mean(cty, na.rm = TRUE), median_cty = median(cty, na.rm = TRUE))ggplot2 for plotting
ggplot(mpg, aes(x = cty)) + geom_histogram()+ labs(x = 'City Mileage')ggplot(mpg, aes(x = cty, y = hwy)) + geom_point()+ geom_smooth(method = 'lm')aes(color = class)+ scale_color_brewer(palette = 'Dark2')File -> New File -> R Markdownknit buttonlibrary(tidyverse), glimpse(mpg)# to add comments