[R] Assigning values to several consecutives rows in a sequence while leaving some empty

nymphita sandrablazquezcabrera at gmail.com
Mon Oct 22 06:39:45 CEST 2012


Hello all,
I'm trying to group several consecutives rows (and assigning them the same
value) while leaving some of the rows empty (when a certain condition is not
fulfilled).

My data are locations (xy coordinates), the date/time at which they were
measured, and the time span between measures. Somehow simplified, they look
like this:

<http://r.789695.n4.nabble.com/file/n4646956/image1.png> 

I'd like to assign a value to every sequence of locations that are measured
within a time span of 4 hours, and make my data look like this:

<http://r.789695.n4.nabble.com/file/n4646956/image2.png> 

I've tried several algorithms with a loop "for" plus "ifelse" condition
like: 

Sequence <- for (i in 1:max(ID)) {
   ifelse (Span <= 4, i+1, "NA")
}

without any luck. I know my attempt is incorrect, but my programming skills
are really basic and I haven't found any similar problem in the web.

Any ideas would be very appreciated!



--
View this message in context: http://r.789695.n4.nabble.com/Assigning-values-to-several-consecutives-rows-in-a-sequence-while-leaving-some-empty-tp4646956.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list