Hi, netters, This is probably a rookie question but I couldn't find the answer after hours of searching and trying. Suppose there'a a dataframe M: x y 10 A 13 B 8 A 11 A I want to locate the rows where x >=10 and y="A". I know how to do it to vectors by using which, but how to do it with the dataframe? Thank you very much! Zhihua Li _________________________________________________________________ MSN ÖÐÎÄÍø£¬×îÐÂʱÉÐÉú»î×ÊѶ£¬°×Áì¾Û¼¯ÃÅ»§¡£ [[alternative HTML version deleted]]
Charilaos Skiadas
2008-Mar-07 15:56 UTC
[R] locate the rows in a dataframe with some criteria
On Mar 7, 2008, at 10:50 AM, zhihuali wrote:> > Hi, netters, > > This is probably a rookie question but I couldn't find the answer > after hours of searching and trying. > > Suppose there'a a dataframe M: > > x y > 10 A > 13 B > 8 A > 11 A > > I want to locate the rows where x >=10 and y="A". I know how to do > it to vectors by using > which, but how to do it with the dataframe? >Does ?subset do what you want?> Thank you very much! > > > Zhihua Li >Haris Skiadas Department of Mathematics and Computer Science Hanover College
Un texte encapsul? et encod? dans un jeu de caract?res inconnu a ?t? nettoy?... Nom : non disponible Url : https://stat.ethz.ch/pipermail/r-help/attachments/20080307/3424129d/attachment.pl
Henrique Dallazuanna
2008-Mar-07 16:03 UTC
[R] locate the rows in a dataframe with some criteria
Try: with(m, which((x >= 10 & y == "A"))) On 07/03/2008, zhihuali <lzhtom at hotmail.com> wrote:> > Hi, netters, > > This is probably a rookie question but I couldn't find the answer after hours of searching and trying. > > Suppose there'a a dataframe M: > > x y > 10 A > 13 B > 8 A > 11 A > > I want to locate the rows where x >=10 and y="A". I know how to do it to vectors by using > which, but how to do it with the dataframe? > > Thank you very much! > > > Zhihua Li > > > _________________________________________________________________ > MSN ???????????????????? > > [[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. > >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Bill.Venables at csiro.au
2008-Mar-08 01:48 UTC
[R] locate the rows in a dataframe with some criteria
i <- with(M, which(x >= 10 & y == "A")) ## will get you the row indices. m <- subset(M, x >= 10 & y == "A") ## will get you the rows themselves -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of zhihuali Sent: Saturday, 8 March 2008 1:51 AM To: r-help at stat.math.ethz.ch Subject: [R] locate the rows in a dataframe with some criteria Hi, netters, This is probably a rookie question but I couldn't find the answer after hours of searching and trying. Suppose there'a a dataframe M: x y 10 A 13 B 8 A 11 A I want to locate the rows where x >=10 and y="A". I know how to do it to vectors by using which, but how to do it with the dataframe? Thank you very much! Zhihua Li _________________________________________________________________ MSN ???????????????????????????????????????? [[alternative HTML version deleted]]
Reasonably Related Threads
- An R clause to bind dataframes under certain contions
- Comparison of aggregate in R and group by in mysql
- how to use a function in aggregate which accepts matrix and outputs matrix?
- Error: evaluation nested too deeply when doing heatmap with binary distfunction
- sort a data matrix by all the values and keep the names