The lab sheet can be found here.
Support Material
R Cheatsheets
-
Full manual here.
-
Short reference card.
-
Examples here.
-
Typical user wiki.
Notes
-
R is case-sensitive, so
view
doesn’t work butView
does. -
When a data point is not available we use NA:
j = c(1,2,NA)
.- If you want to compute anyways:
max(j, na.rm=TRUE)
.
- If you want to compute anyways:
Creating Scatterplots
- Column name:
plot(mydata$column1, mydata$column2)
- Column location:
plot(mydata[,9], mydata[,11])
- Histogram:
hist(mydata$temp)
- Line plot:
plot(mydata$temp, type="l")
- Plot colours, for example X and Y according to temperature:
plot(mydata$X, mydata$Y, col=mydata$temp)
- Statistics:
- Mean, median, maximum and minimum:
meantemp = mean(mydata$temp)
- Mean, median, maximum and minimum:
- Write to a file:
write.csv(meantemp, file = "output.csv")
- Build a linear model:
plot(mydata$temp, mydata$ISI) lmfire=line(mydata$ISI~mydata$temp) abline(coef(lmfire))
Commands
mydata = read.csv('/Users/pietra/projects/university/year3/cs3002/lab1/forestfires.csv', sep=',')
plot(mydata)
View(mydata)
plot(mydata$column1, mydata$column2)
plot(mydata[,9], mydata[,11])
hist(mydata$temp)
plot(mydata$temp, type="l")
plot(mydata$X, mydata$Y, col=mydata$temp)
meantemp = mean(mydata$temp)
write.csv(meantemp, file = "output.csv")
plot(mydata$temp, mydata$ISI)
lmfire=line(mydata$ISI~mydata$temp)
abline(coef(lmfire))