[R] Conditional Counting with Table

Gustavo Carvalho gustavo.bio+R at gmail.com
Wed Dec 24 06:28:27 CET 2008


Hello,

Something like this should work:

table(test$V1[!test$V2 %in% c("NM","QC")])

Cheers,

Gustavo.

On Wed, Dec 24, 2008 at 3:06 AM, Gundala Viswanath <gundalav at gmail.com> wrote:
> Dear all,
>
> I have the following data frame:
>
> V1     V2
> aaa    chr1
> aaa    chr2
> aaa    NM
> aaa    QC
> aaa    chr10
> att      NM
> att      chr7
>
> What I want to do is to count the string (V1).
> But the condition of counting is: if the V2 of the string
> is "NM" or "QC"  then the count is not increased.
>
> Hence the contigency table will look like this:
>
> #tag       count
> aaa  3
> att    1
>
> Is there a compact way to achieve that in R?
> I am thinking of using "table" but can't see
> how to impose such condition into it.
>
>
> - Gundala Viswanath
> Jakarta - Indonesia
>
> ______________________________________________
> 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