#what is R #what is R Studio #play with numbers!!! # also, ctrl + Enter (shortcut to run code) #ctrl + 1 (go to script pane) # ctrl + 2 (go to R Console) ob <- 3 ob1 <- 2 answer <- ob + ob1 answer ### working with data ### #built in data iris ire <- iris #look at top of data head(ire) #adding and "area" column to iris ire$Sepal.Area <- ire$Sepal.Length * ire$Sepal.Width head(ire) str(ire) #saving data #where is the file going!?!?!? setwd([filepath]) write.csv(x = ire, file = "Irisdata.csv") write.csv(ire, "Irisdata.csv") #bringing in data d <- read.csv("Irisdata.csv") #remove object we don't care about rm(ire) ls() ### modeling and visualization ### #plotting and a simple model p <- plot(Sepal.Area ~ Petal.Width, data = d, col = Species) mod <- lm(Sepal.Area ~ Petal.Width, data = d) p abline(mod) ### Gettin' fancy with packages ### #speedin' it up with dplyr <- take data and add new columns install.packages("dplyr") library(dplyr) d %>% group_by(Species) %>% summarize(avg = mean(Petal.Length)) #fancyin' it up with ggplot library(ggplot2) pg <- ggplot(data = d, aes(x = Petal.Width, y = Sepal.Area, color = Species)) summary(mod) pg + geom_point() + geom_abline(intercept = coef(mod)["(Intercept)"], slope = coef(mod)["Petal.Width"]) + facet_grid(facets = Species ~.)