Hi, I have a two columns data, the first column are values, and second column are the groups. For this example, there are 3 groups 1,2,3. How can I manipulate the values in the first column according to groups, say I would like to find mean, sum, and standard deviation for the different groups ? How do I plot data according to groups ?> t <- matrix(c(rnorm(10), 1,1,2,2,1,3,3,3,3,2), ncol=2)[[alternative HTML version deleted]]
Look at ?tapply, based on your description, it is what you want. Ben -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Ng Stanley Sent: Thursday, March 13, 2008 9:25 AM To: r-help Subject: [PS] [R] How to manipulate data according to groups ? Hi, I have a two columns data, the first column are values, and second column are the groups. For this example, there are 3 groups 1,2,3. How can I manipulate the values in the first column according to groups, say I would like to find mean, sum, and standard deviation for the different groups ? How do I plot data according to groups ?> t <- matrix(c(rnorm(10), 1,1,2,2,1,3,3,3,3,2), ncol=2)[[alternative HTML version deleted]] ______________________________________________ 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.
?aggregate tt <- matrix(c(rnorm(10), 1,1,2,2,1,3,3,3,3,2), ncol=2)) aggregate(t[,1], by=list(t[,2]), mean) should work --- Ng Stanley <stanleyngkl at gmail.com> wrote:> Hi, > > I have a two columns data, the first column are > values, and second column > are the groups. For this example, there are 3 groups > 1,2,3. > > How can I manipulate the values in the first column > according to groups, say > I would like to find mean, sum, and standard > deviation for the different > groups ? How do I plot data according to groups ? > > > t <- matrix(c(rnorm(10), 1,1,2,2,1,3,3,3,3,2), > ncol=2) > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
Seemingly Similar Threads
- indices of rows containing one or more elements >0
- counts of each column that are not NA, and/or greater than column means
- How to cbind or rbind different lengths vectors/arrays without repeating the elements of the shorter vectors/arrays ?
- how to write a table to pdf
- Conditional rows