This works too! Thank you.
Such a relief after few days spent on trying to solve it.
Lilia
On 13 March 2013 19:52, jim holtman wrote:
> I forgot the 'seq':
>
> > data=data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2))
> > data$tripid <- cumsum(c(TRUE, diff(data$beh) != 0))
> > data$seq <- ave
#10 10 2 2 4
> A.K.
>
>
>
>
> - Original Message -
> From: Lilia Dmitrieva
> To: r-help@r-project.org
> Cc:
> Sent: Wednesday, March 13, 2013 3:05 PM
> Subject: [R] Assign the number to each group of multiple rows
>
> Dear R users,
>
>
>
&
I forgot the 'seq':
> data=data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2))
> data$tripid <- cumsum(c(TRUE, diff(data$beh) != 0))
> data$seq <- ave(data$beh, data$tripid, FUN = function(x) seq_along(x))
> data
row beh tripid seq
11 1 1 1
22 1 1 2
33 1 1
try this:
> data=data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2))
> data$tripid <- cumsum(c(TRUE, diff(data$beh) != 0))
> data
row beh tripid
11 1 1
22 1 1
33 1 1
44 2 2
55 2 2
66 2 2
77 1 3
88 1 3
9
] Assign the number to each group of multiple rows
Dear R users,
My data have repeating "beh" parameter : 1 or 2 - type of animal behavior
in subsequent locations. I need to assign unique number to each sequence of
locations.
My data is:
>data=data.frame(row=seq(1:10),beh=c(1,1,1,2,2
Dear R users,
My data have repeating "beh" parameter : 1 or 2 - type of animal behavior
in subsequent locations. I need to assign unique number to each sequence of
locations.
My data is:
>data=data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2))
>attach(data)
>data
row beh
111
6 matches
Mail list logo