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]]
?table On 14/01/2010, at 11:12 AM, 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.###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
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
Hi Jesse, If your vector is called "aa", then how about:> table(aa)aa spp1 spp10 spp2 spp3 spp4 spp5 spp6 spp7 spp8 spp9 7 2 16 8 15 9 9 10 9 15 Hope this helps, Adrian On Thursday 14 January 2010, 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]] >-- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd. 050025 Bucharest sector 5 Romania Tel.:+40 21 3126618 \ +40 21 3120210 / int.101 Fax: +40 21 3158391