[R] How to count rows with a condition

arun smartpink111 at yahoo.com
Wed Oct 17 23:43:53 CEST 2012


HI, 
I tried the code with unsorted ac_names column and found to be 
working.  So, couldn't identify exactly the problem.  If you can provide
 a subset of your dataset using ?dput(), then it would be much helpful. 

set.seed(1) 
dat1<-data.frame(ac_name=sample(c("HouseA","HouseB","HouseC","HouseD","HouseE","HouseF","HouseG","HouseI","HouseJ"),50,replace=TRUE),val=rnorm(50,15)) 
dat2<-within(dat1,{ac_name<-as.character(ac_name)}) 
dat2<-dat2[order(dat2[,1]),] 
 dat3<-dat2[dat2[,1]%in%count(dat2[,1])$x[count(dat2[,1])[2]>5],] #data excluded 
dat4<-dat2[!dat2[,1]%in%count(dat2[,1])$x[count(dat2[,1])[2]>5],] #data included 
A.K. 


----- Original Message -----
From: fxen3k <f.sehardt at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Wednesday, October 17, 2012 9:57 AM
Subject: Re: [R] How to count rows with a condition

Thanks for the first reply. 

Unfortunately, my list of different ac_names ist pretty long (about 1,000
different names). Is there a way, to sort them, count the quantity of each
name and exclude these rows, who exceed a particular limit?



--
View this message in context: http://r.789695.n4.nabble.com/How-to-count-rows-with-a-condition-tp4646454p4646465.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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