?ave
> a
[1] 2 3 3 4
> cbind(a, ave(a, a, FUN=length))
a
[1,] 2 1
[2,] 3 2
[3,] 3 2
[4,] 4 1
>
On Sun, Feb 6, 2011 at 8:21 PM, Carrie Li wrote:
> Hello R-helpers,
>
> I have a question about counting numbers.
> Here is a simple example.
>
> a=c(2, 3, 3,4)
>> table(a)
> a
> 2 3 4
> 1 2 1
>
Many thanks!
all methods work well! thanks again!
On Sun, Feb 6, 2011 at 8:42 PM, Ray Brownrigg
wrote:
> It's not quite clear what the OP really wanted. A more general solution
> may be:
>
> > a=c(4, 3, 2, 3)
> > ta <- table(a)
> > ta
> a
> 2 3 4
> 1 2 1
> > ta[as.character(a)]
> a
> 4 3 2 3
> 1
It's not quite clear what the OP really wanted. A more general solution may be:
> a=c(4, 3, 2, 3)
> ta <- table(a)
> ta
a
2 3 4
1 2 1
> ta[as.character(a)]
a
4 3 2 3
1 2 1 2
>
HTH
Ray Brownrigg
On Mon, 07 Feb 2011, Jorge Ivan Velez wrote:
> Hi
Hi Carrie,
Try
> x <- rle(a)
> rep(x$lengths, x$lengths)
[1] 1 2 2 1
HTH,
Jorge
On Sun, Feb 6, 2011 at 8:21 PM, Carrie Li <> wrote:
> Hello R-helpers,
>
> I have a question about counting numbers.
> Here is a simple example.
>
> a=c(2, 3, 3,4)
> > table(a)
> a
> 2 3 4
> 1 2 1
>
> so, I can to
Hello R-helpers,
I have a question about counting numbers.
Here is a simple example.
a=c(2, 3, 3,4)
> table(a)
a
2 3 4
1 2 1
so, I can to create another variables that has the corresponding counting
numbers.
In this case, I want to have:
b=c(1,2,2,1)
Is there any way coding for this ?
Thanks
5 matches
Mail list logo