Skip to content
Prev 311752 / 398503 Next

R help..subsetting data frame that meeting multiple criteria

Hi David,
Tried the solution on a slightly different data:
dat <- read.table(text="
value class percent
15526 36 4.6875
15527 62 85.9375
15527 82 32.4564
15528 36 70.3125
15528 62 9.375
15528 82 74.6875
15529 72 50.0000
15530 72 50.0000
", header = TRUE)
dat.a <- dat[ dat[["class"]] %in% dat[ dat[["percent"]] >70, "class"] , ]
?row.names(dat.a) <- unlist(tapply(dat.a$class, dat.a$class, function(x) paste0(x, letters[1:length(x)])))
?dat.a
#??? value class percent
#36a 15526??? 36? 4.6875
#36b 15527??? 62 85.9375
#62a 15527??? 82 32.4564
#62b 15528??? 36 70.3125
#82a 15528??? 62? 9.3750
#82b 15528??? 82 74.6875


A.K.




----- Original Message -----
From: David Winsemius <dwinsemius at comcast.net>
To: prasmas <prasad4rr at gmail.com>
Cc: r-help at r-project.org
Sent: Friday, November 23, 2012 7:40 PM
Subject: Re: [R] R help..subsetting data frame that meeting multiple criteria
On Nov 23, 2012, at 1:14 PM, prasmas wrote:

            
? value class percent
1 15526? ? 36? 4.6875
2 15527? ? 62 85.9375
3 15527? ? 82 32.4564
4 15528? ? 36 70.3125
5 15528? ? 62? 9.3750
6 15528? ? 82 74.6875
? ? value class percent
36a 15526? ? 36? 4.6875
36b 15527? ? 62 85.9375
62a 15527? ? 82 32.4564
62b 15528? ? 36 70.3125
82a 15528? ? 62? 9.3750
82b 15528? ? 82 74.6875

You can split by the NROW of dat.a if you want.

--David.
David Winsemius, MD
Alameda, CA, USA

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