[R] Counting the occurence of each unique "charecter string"

Chuck Cleland ccleland at optonline.net
Sun Nov 27 19:06:28 CET 2005


?table

table(mydata$species)

Marco Visser wrote:
> LS,
>   
>   I would really like to know how to count the frequency/occurrence of  chachters inside a dataset. I am working with extreemly large datasets  of forest inventory data with a large variety of different species  inside it. 
>   Each row inside the dataframe represents one individual tree and the simplified dataframe looks something like this:
>   
>   num species dbh   
>   1        sp1           30
>   2        sp1          20
>   3        sp2          30
>   4        sp1          40
>   
>   I need to be able to count the number of individuals per species, so I  need a command that will return for each unique species its occurence  inside the dataframe; 
>   
>   [sp1]     3
>   [sp2]     1
>   
>   After a long search through help.search() and the web I found very  little and any alternative like exporting the dataset to another  program(excel) is not really an option because the dataset is far to  large.
>   
>   I am using R 2.2.0 in Windows and if anyone knows a solution please help!
>   
>   Many sincere thanks in advance,
>   
>   Marco 
>   
>   
>   
> 		
> ---------------------------------
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894




More information about the R-help mailing list