[R] sorting a data.frame by mean values of grouped data
sjbarry
sjb78 at uow.edu.au
Thu Mar 13 05:39:37 CET 2008
Hi,
I have what I think is a fairly straightforward problem. I've looked
through the FAQ's and mailing lists but have been unable to identify a
solution, probably because I don't understand the language well enough.
I have a set of data d, with 3 columns as shown,
I want to sort the data Group, mean(Value by Label). I know that this
can be done for one level, say Label, using factor() but I cannot see
how to extend that. I have included the code to create the data.frame
below and would greatly appreciate a solution or a link to a similar
problem that has already been solved in the mailing list.
Value Label Group
19 Big A
29 Big A
39 Big A
55 Small D
33 Small D
11 Small D
55 Small D
66 Small D
11 Small D
2 Big C
3 Big C
3 Big C
3 Big C
3 Big C
3 Big C
3 Big C
3 Small B
2 Small B
5 Small B
6 Small B
5 Small B
6 Small B
Value <- c(19,29,39,55,33,11,55,66,11,2,3,3,3,3,3,3,3,2,5,6,5,6)
Group <- c("A","A","A","D","D","D","D","D","D",
"C","C","C","C","C","C","C","B","B","B","B","B","B")
Label <- c("Big","Big","Big",
"Small","Small","Small","Small","Small","Small",
"Big","Big","Big","Big","Big","Big","Big",
"Small","Small","Small","Small","Small","Small")
d <- as.data.frame(cbind(Value, Label, Group))
Thanks
Stephen Barry
--
School of Earth and Environmental Sciences
University of Wollongong
Northfields Ave.
Wollongong, NSW. 2522
Australia
More information about the R-help
mailing list