Here's another one: match(d, unique(d)).
Arun
From:Â Greg Snow 538...@gmail.com
Reply:Â Greg Snow 538...@gmail.com
Date:Â March 12, 2014 at 8:41:31 PM
To:Â T Bal studentt...@gmail.com
Cc:Â r-help r-help@r-project.org
Subject:Â Re: [R] Assign numbers in R
Here are a couple more optio
Here are a couple more options if you want some variety:
> d <- c(8,7,5,5,3,3,2,1,1,1)
> as.numeric( factor(d, levels=unique(d)) )
[1] 1 2 3 3 4 4 5 6 6 6
> cumsum( !duplicated(d) )
[1] 1 2 3 3 4 4 5 6 6 6
What would you want the output to be if your d vector had another 8
after the last 1? T
almazó: T Bal [studentt...@gmail.com]
> Küldve: 2014. március 12. 10:13
> To: r-help@r-project.org
> Tárgy: [R] Assign numbers in R
>
> Hi,
> I have the following numbers:
>
> d <- c(8,7,5,5,3,3,2,1,1,1)
>
> I want to convert these into the following numbers:
>
&g
Hi,
Try:
cumsum(c(TRUE,d[-1]!=d[-length(d)]))
A.K.
On Wednesday, March 12, 2014 5:28 AM, T Bal wrote:
Hi,
I have the following numbers:
d <- c(8,7,5,5,3,3,2,1,1,1)
I want to convert these into the following numbers:
r:
1,2,3,3,4,4,5,6,6,6
So if two numbers are different increment it if t
Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ;
meghatalmazó: T Bal [studentt...@gmail.com]
Küldve: 2014. március 12. 10:13
To: r-help@r-project.org
Tárgy: [R] Assign numbers in R
Hi,
I have the following numbers:
d <- c(8,7,5,5,3,3,2,1,1,1)
I want to convert these
Hello,
Try the following.
r <- cumsum(c(TRUE, diff(d) != 0))
Hope this helps,
Rui Barradas
Em 12-03-2014 09:13, T Bal escreveu:
Hi,
I have the following numbers:
d <- c(8,7,5,5,3,3,2,1,1,1)
I want to convert these into the following numbers:
r:
1,2,3,3,4,4,5,6,6,6
So if two numbers are
Hello,
For your example, the following will work:
R> d <- c(8,7,5,5,3,3,2,1,1,1)
R> idx <- 1:length(unique(d))
R> rep(idx, rle(d)$length)
[1] 1 2 3 3 4 4 5 6 6 6
HTH,
Pascal
On Wed, Mar 12, 2014 at 6:13 PM, T Bal wrote:
> Hi,
> I have the following numbers:
>
> d <- c(8,7,5,5,3,3,2,1,1,1)
>
>
Hi,
I have the following numbers:
d <- c(8,7,5,5,3,3,2,1,1,1)
I want to convert these into the following numbers:
r:
1,2,3,3,4,4,5,6,6,6
So if two numbers are different increment it if they are same then assign
the same number:
r <- NULL
for (i in 1:length(d)) {
if (d[i] != d[i+1]) {
r[i]
8 matches
Mail list logo