split(data, group)
Within each group, data values are ordered as they originally appeared in data. The name of the component is the corresponding value in group, or the corresponding category name.
split(c("Martin", "Mary", "Matt"), c("M", "F", "M"))attach(market.frame) boxplot(split(age, employment), notch = TRUE)
sapply(split(income,age), mean) # mean income level by age tapply(income,list(age), mean) # alternative computation
split(people,age %/% 10) # by decades split(ship, cycle(ship)) #component for each month attach(lung) split(time, sex) # survival time by sex
split(x, group = slice.index(x,2)) # compare to x[,1,], x[,2,], x[,3,]
# Produces the following output: $"1": [1] 101 102 103 104 113 114 115 116
$"2": [1] 105 106 107 108 117 118 119 120
$"3": [1] 109 110 111 112 121 122 123 124