[R] How to obtain a cross tab count of unique values

Rui Barradas ruipbarradas at sapo.pt
Tue Mar 31 22:40:49 CEST 2015


Hello,

Try the following.

table(unique(df)$PROJECT)


And please note that 'df' is the name of an R function, use something else.

Hope this helps,

Rui Barradas

Em 31-03-2015 20:51, Walter Anderson escreveu:
> I have a data frame that shows all of the parks (including duplicates)
> that are impacted by a projects 'footprint':
>
> PROJECT PARKNAME
> A       PRK A
> A       PRK B
> A       PRK A
> B       PRK C
> B       PRK A
> C       PRK B
> C       PRK D
> ...
>
> What I need is a cross tabulation that shows me the number of unique
> parks for each project.  If I using the standard table(df$PROJECT) it
> reports:
>
> A 3
> B 2
> C 2
> ...
>
> where I need it to ignore duplicates and report:
>
> A 2
> B 2
> C 2
> ...
>
> Anyone have any suggestions on how to do this within the R paradigm?
>
> Walter Anderson
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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