> state <- c(1,4,2,1,5,0) > statef <- factor(state) > statef [1] 1 4 2 1 5 0 Levels: 0 1 2 4 5 > levels(statef) [1] "0" "1" "2" "4" "5" > levels(factor(state)) [1] "0" "1" "2" "4" "5" >
> members <- c("lee", "kim", "park", "song", "kang", "lee", "kang") > incomes <- c(100, 10, 45, 122, 549, 12, 94) > tapply(incomes, members, mean) kang kim lee park song 321.5 10.0 56.0 45.0 122.0 > tapply(incomes, members, max) kang kim lee park song 549 10 100 45 122 > tapply(incomes, members, min) kang kim lee park song 94 10 12 45 122 > tapply(members, incomes, min) 10 12 45 94 100 122 549 "kim" "lee" "park" "kang" "lee" "song" "kang" >