Displaying 1 result from an estimated 1 matches for "sp_maj".
Did you mean:
sp_max
2009 Feb 12
3
Aggregrate function
...t;, 2))
sp <- c("a", "b", "c", "a", "d", "b", "e", "c", "b", "d")
tot <- c(20, 60, 40, 15, 25, 10, 30, 20, 68, 32)
xveg <- data.frame(loc, sp, tot)
result desired:
L1 b
L2 e
L3 b
sp_maj <- aggregate(xveg[,2], list(xveg[,1], function(x) levels(x)[which.max(table(x))])
This is wrong because it gives the first species name in each level of location, so i get a, a, b, as species instead of b, e, b.
I've tried other few aggregate commands, all with wrong results.
I will ap...