[R] Odp: Counting rows given conditional
Petr PIKAL
petr.pikal at precheza.cz
Thu Aug 4 15:08:08 CEST 2011
Hi
r-help-bounces at r-project.org napsal dne 04.08.2011 14:56:09:
> a217 <ajn21 at case.edu>
> Odeslal: r-help-bounces at r-project.org
>
> 04.08.2011 14:56
>
> Komu
>
> r-help at r-project.org
>
> Kopie
>
> Předmět
>
> [R] Counting rows given conditional
>
> 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.
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
>
> 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.
>
> ______________________________________________
> 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