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

Tom Wright tom at maladmin.com
Tue Mar 31 22:42:50 CEST 2015


table(unique(df)$PROJECT)

On Tue, 2015-03-31 at 14:51 -0500, Walter Anderson wrote:
> 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