Hi,
May be this helps:
set.seed(14)
dat1 <- data.frame(shell_ID=
sample(c("0208A_47_33","0208A_47_34","0912C_13_3","1400C_2_48"),20,replace=TRUE),stringsAsFactors=FALSE)
dat2 <- dat1
ord1 <-
order(as.numeric(gsub("[[:alpha:]]+.*","",dat1$shell_ID)),as.numeric(gsub(".*\\_","",dat1$shell_ID))
)
om: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> Of William Dunlap
> Sent: Friday, October 11, 2013 9:51 AM
> To: arun; Steven Ranney; r-help@r-project.org
> Subject: Re: [R] Create sequential vector for values in another column
>
> At this poin
Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> Of arun
> Sent: Friday, October 11, 2013 6:43 AM
> To: Steven Ranney; r-help@r-project.org
> Subject: Re: [R] Create sequential vector for values in another col
On 11-10-2013, at 15:26, Steven Ranney wrote:
> Hello all -
>
> I have an example column in a dataFrame
>
> id.name
> 123.45
> 123.45
> 123.45
> 123.45
> 234.56
> 234.56
> 234.56
> 234.56
> 234.56
> 234.56
> 234.56
> 345.67
> 345.67
> 345.67
> 456.78
> 456.78
> 456.78
> 456.78
> 456.78
> 456.7
Hi
I named your data test
test$x<-1
test$x<-unlist(lapply(split(test$x, test$id.name), cumsum))
> test
id.name x
1 123.45 1
2 123.45 2
3 123.45 3
4 123.45 4
5 234.56 1
6 234.56 2
7 234.56 3
8 234.56 4
9 234.56 5
10 234.56 6
11 234.56 7
12 345.67 1
13 345.67 2
14 345.67 3
Also,
it might be faster to use ?data.table()
library(data.table)
dt1<- data.table(dat1,key='id.name')
dt1[,x:=seq(.N),by='id.name']
A.K.
On , arun wrote:
Hi,
Try:
dat1<-
structure(list(id.name = c(123.45, 123.45, 123.45, 123.45, 234.56,
234.56, 234.56, 234.56, 234.56, 234.56, 234.56, 345
6 matches
Mail list logo