[R] sorting a data.frame by mean values of grouped data

From: sjbarry <sjb78_at_uow.edu.au>
Date: Thu, 13 Mar 2008 15:39:37 +1100


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

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 13 Mar 2008 - 04:45:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 13 Mar 2008 - 05:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive