# R solutions for in-class tasks. MAS115 Sem 2, Lab Class 4
# 2.3 Tasks solutions
# 1.
PlantTrial <- data.frame(Species=c("Green","Green","Blue","Blue"),
Treatment=c("A","B","A","B"),
Yield=c(10.1,15.5,2.3,7.6),
Height=c(8.2,12.3,9.1,20.3))
# 2.
# a) Using ?mtcars, qsec is the "1/4 mile time".
# Online search tells us that this is the time in seconds taken
# to travel 1/4 mile from a standing start.
# b)
head(mtcars)
# or
mtcars["Datsun 710","qsec"]
# gives us an answer of 18.61.
# c) numerical, using
str(mtcars)
# d)
mtcars[mtcars$cyl==4,]
# e) There are many ways, but one is
mtcars$mpg[mtcars$am==0]
# to get the relevant numbers, and so
mean(mtcars$mpg[mtcars$am==0])
# to get their mean. Alternatively
mean(mtcars[mtcars$am==0,"mpg"])
# f)
mtcars["Ferrari Dino",]
# 3.2 Tasks solutions
# 1.
sysamp <- runif(20)
# 2.
mylist <- list(a=sysamp,b=PlantTrial)
# 3.
mylist[1]
# gives a list of one vector.
# Compare
mylist[[1]]
list(mylist[[1]])
# 4.
mylist[[2]]