the tapply function
- tapply(veg$R, veg$Transect, mean)
- tapply (x = veg$R, INDEX = veg$Transact, FUN = mean)
o splits the data of the first variable, based on levels of the second variable
the sapply and lapply functions
- laborious if we wish to calculate mean of large number of variables
- example
o 20 numerical variables in vegetation dataset
o sapply(veg[,5:9, FUN = mean)
- differences
o tapply
§ calculates mean (or other function) for subsets of observations of a variable
o lapply / sapply
§ calculate mean etc of one / more variables, using all observations
§ difference
· presentation of output
o lapply – presented as list
o sapply – gives it as vector
summary function
- argument – can be
o variable
o output from cbind function
o data frame
- example
o z <- cbind(veg$R, veg$ROCK, veg$LITTER)
o colnames(z) <- c("R", "ROCK", "LITTER")
o summary(z)
- example
o summary(veg[, c("R", "ROCK", "LITTER"(])
- example
o summary(veg[, c(5,6,7)])
Table Function
- observations per farm
o table(Deer$Farm)
- observations per year, by sex
o table(Deer$Sex,Deer$Year)
No comments:
Post a Comment