[R] counting the number of times a string appears

Greg Hirson ghirson at ucdavis.edu
Wed Jan 13 23:23:49 CET 2010


Jesse,

see ?table and try

table(stringVector)

Greg

On 1/13/10 2:12 PM, Jesse Sinclair wrote:
> Hi all,
>
> I have a vector of strings and need to count the number of times a string
> appears in the vector.
>
> eg:
>
>   [1] spp6  spp10 spp6  spp6  spp4  spp2  spp9  spp10 spp5  spp2  spp2  spp3
>   [13] spp4  spp3  spp6  spp10 spp6  spp4  spp9  spp3  spp6  spp1  spp10 spp8
>
>   [25] spp2  spp10 spp9  spp7  spp1  spp3  spp8  spp6  spp3  spp8  spp6  spp5
>
>   [37] spp5  spp9  spp3  spp1  spp4  spp5  spp9  spp3  spp3  spp5  spp4  spp9
>
>   [49] spp3  spp7  spp7  spp2  spp6  spp5  spp7  spp4  spp8  spp9  spp2  spp6
>
>   [61] spp3  spp3  spp2  spp6  spp3  spp5  spp6  spp6  spp4  spp1  spp1  spp1
>
>   [73] spp10 spp8  spp1  spp6  spp1  spp5  spp8  spp9  spp5  spp6  spp9
> spp10
>   [85] spp2  spp6  spp10 spp1  spp2  spp3  spp5  spp8  spp2  spp7  spp4  spp7
>
>   [97] spp2  spp6  spp2  spp6
>
> Is it possible to create a vector of counts for each spp1-spp10?
>
> Any help or ideas would be appreciated.
>
> Cheers,
> Jesse
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>    

-- 
Greg Hirson
ghirson at ucdavis.edu

Graduate Student
Agricultural and Environmental Chemistry

1106 Robert Mondavi Institute North
One Shields Avenue
Davis, CA 95616



More information about the R-help mailing list