Math 50, R Basics
Do not just read this document. Type each of the below commands in RStudio and get help from your R-group if needed.
4+3*2
c(1,12,123)
help(c)
myVector<-c(1,12,123)
myVector
runif(n=5, min=10, max=20)
rnorm(n=5, mean = 11, sd = 7)
myData<-rnorm(n=100, mean = 11, sd = 7)
mean(myData)
var(myData)
sd(myData)
prop<-read.table("https://math.dartmouth.edu/~m50f17/propellant.csv")
prop
prop<-read.table("https://math.dartmouth.edu/~m50f17/propellant.csv", header=T)
prop
prop<-read.table("https://math.dartmouth.edu/~m50f17/propellant.csv", header=T, sep=”,”)
str(prop)
summary(prop)
fix(prop)
prop$Age
prop[[2]]
mean(prop[[2]])
attach(prop)
Age
mean(Age)
plot(prop)
plot(Age,ShearS)
plot(Age,ShearS, ylim=c(1600,2700))
propReverseOrder<-prop[2:1]
plot(propReverseOrder)
fitted<-lm(formula= ShearS ~ Age)
summary(fitted)
abline(fitted$coef, lwd=2, col=’blue’)
(Excercise try to use lm(formula= Age ~ ShearS) and see why it wont draw the line.
prop<-read.table("https://math.dartmouth.edu/~m50f17/propellant.csv", header=T, sep=",")
Age<-prop$Age
ShearS<-prop$ShearS
plot(Age,ShearS)
fitted<-lm(formula= ShearS ~ Age)
abline(fitted$coef, lwd=2, col=’blue’)
N<-length(Age)
yHat <- predict(fitted)
for (k in 1:N) lines(c(Age[k], Age[k]), c(ShearS[k], yHat[k]))