[R] how to fetch rows with certain characteristics

Viechtbauer Wolfgang (STAT) Wolfgang.Viechtbauer at STAT.unimaas.nl
Thu Oct 29 07:56:55 CET 2009


tapply(x, y, min)

where x is the vector of numbers and y the vector of class labels.

Best,

--
Wolfgang Viechtbauer                        http://www.wvbauer.com/
Department of Methodology and Statistics    Tel: +31 (0)43 388-2277
School for Public Health and Primary Care   Office Location:
Maastricht University, P.O. Box 616         Room B2.01 (second floor)
6200 MD Maastricht, The Netherlands         Debyeplein 1 (Randwyck)
________________________________________
From: r-help-bounces at r-project.org [r-help-bounces at r-project.org] On Behalf Of Waverley @ Palo Alto [waverley.paloalto at gmail.com]
Sent: Thursday, October 29, 2009 6:47 AM
To: r-help
Subject: [R] how to fetch rows with certain characteristics

Hi,

I have a matrix, first column is of certain values, second column is
the class labels or a factor.
e.g.

1.2 1
1.3 1
1.3 1
1.5 1
2.1 2
2.0 2
9.9 2
1.4 3
1.8 3
1.9 3

I want to find out what is the min values of column 1 for each
corresponding class (column 2).  For the above example, I want to
return a matrix of
1.2 1
2.0 2
1.3 3

Can someone suggest how to code for that?  The second column can be of
characters.

Thanks much.


--
Waverley @ Palo Alto

______________________________________________
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.



More information about the R-help mailing list