The lab sheet can be found here.

Support Material

R Cheatsheets


Notes


  • R is case-sensitive, so view doesn’t work but View 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).

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)
  • 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))