R, basic function

addition = function(num1,num2){
answer = num1+num2
return(answer)
}
addition(10,9)
addition(5,4)

Thanks Isaac!

 

Use "" if dealing with a string.

addition = function(x1){
x1 = 2+3
return(x1)
}
addition(”kaz”)
addition(”john”)

Studying R on datacamp

My memo

 

library(gapminder)
library(dplyr)
library(ggplot2)

# Summarize the median GDP and median life expectancy per continent in 2007
by_continent_2007 <- gapminder %>%
filter(year == 2007) %>%
group_by(continent) %>%
summarize(medianGdpPercap = median(gdpPercap),
medianLifeExp = median(lifeExp))

# Use a scatter plot to compare the median GDP and median life expectancy
ggplot(by_continent_2007, aes(x = medianGdpPercap, y = medianLifeExp, color = continent)) +
geom_point()

R regression models

year1<-filter(core2,year==1)
linearMod_y1 <- lm(zpost_test ~ treat + pre_test +Male +Grade09+Grade10+Grade11+Grade12+Other+Black+hispanic+Par_BA+par_edu_miss, data=year1)
print(linearMod_y1)