hi guys Assume I have this dataframe: v3$number_of_ones [1] 111 106 117 108 120 108 108 116 116 113 Is there any command in r that gives me the frequency of these numbers (how many each number is repeated e.g. the number 108 repeated 2 and 111 repeated one an so on) I have around 10^6 number and would like to see how many each number if repeated. Regards ****************************************************************** Bander Alzahrani, [[alternative HTML version deleted]]
If you just need a count of how many of each number you can just use table().> tmp <- c(111,106,117,108,120,108,108,116,113) > table(tmp)tmp 106 108 111 113 116 117 120 1 3 1 1 1 1 1 On Thu, Nov 21, 2013 at 9:10 AM, b. alzahrani <cs_2002@hotmail.com> wrote:> > hi guys > > Assume I have this dataframe: > v3$number_of_ones > [1] 111 106 117 108 120 108 108 116 116 113 > Is there any command in r that gives me the frequency of these numbers > (how many each number is repeated e.g. the number 108 repeated 2 and 111 > repeated one an so on) > > I have around 10^6 number and would like to see how many each number if > repeated. > > Regards > ****************************************************************** > Bander Alzahrani, > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >-- Charles Determan Integrated Biosciences PhD Candidate University of Minnesota [[alternative HTML version deleted]]
Hi, From the dscription, looks like you need ?rle() vec1 <- c(111, 106, 117, 108, 120, 108, 108, 116, 116, 113) ?res <- rle(vec1)$lengths ?names(res) <- rle(vec1)$values ?res[res>1] #108 116 #? 2?? 2 length(res[res>1]) A.K. On Thursday, November 21, 2013 10:12 AM, b. alzahrani <cs_2002 at hotmail.com> wrote: hi guys Assume I have this dataframe: v3$number_of_ones [1] 111 106 117 108 120 108 108 116 116 113 Is there any command in r that gives me the frequency of these numbers (how many each number is repeated e.g. the number 108 repeated 2 and 111 repeated one an so on) I have around 10^6 number and would like to see how many each number if repeated. Regards ****************************************************************** Bander Alzahrani, ??? ??? ??? ? ??? ??? ? ??? [[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.