Skip to content

Counting rows given conditional

2 messages · a217, PIKAL Petr

#
Hello,

I have an input file that contains multiple columns, but the column I'm
concerned about looks like:

"TR"
5
0
4
1
0
2
0

To count all of the rows in the column I know how to do NROW(x$TR) which
gives 7.

However, I would also like to count only the number of rows with values >=1
(i.e. not 0). I've tried NROW(x$TR>=1) which did not give the intended
output.

Do any of you have any suggestions as to where I'm going wrong?



--
View this message in context: http://r.789695.n4.nabble.com/Counting-rows-given-conditional-tp3718541p3718541.html
Sent from the R help mailing list archive at Nabble.com.
#
Hi

r-help-bounces at r-project.org napsal dne 04.08.2011 14:56:09:
You are quite close. 
x$TR>=1
gives you logical vector TRUE/FALSE. You can compute count of TRUE values 
by
sum(logical.vector) e.g.
sum(x$TR>=1)

Regards
Petr
http://r.789695.n4.nabble.com/Counting-rows-
http://www.R-project.org/posting-guide.html