Message-ID: <971536df0902040814i4de0ba8akda2663a19735ade7@mail.gmail.com>
Date: 2009-02-04T16:14:09Z
From: Gabor Grothendieck
Subject: counting entries in vector
In-Reply-To: <97a146780902040719m21b46537h38418f6e4bc89ae1@mail.gmail.com>
Its not clear whether c("bb", "bb", "aa", "aa", "bb") can occur
or if it can how it should be handled but this gives the lengths
of each run and so would give c(2, 2, 1) in that case (as opposed
to c(3, 2)):
rle(k)$lengths
On Wed, Feb 4, 2009 at 10:19 AM, axionator <axionator at gmail.com> wrote:
> Hi all,
> I've a vector with entries, which are all of the same type, e.g. string:
> k <- c("bb", "bb", "bb", "aa", "cc", "cc")
> and want to create a second vector containing the number of each entry
> in k in the same order as in k, i.e.
> c(3, 1, 2)
>
> or:
> k <- c(5,5,5,5,2,2,4)
> => c(4,2,1)
>
> thanks
>
> ______________________________________________
> 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.
>