I’ve got some large data.frames with POSIXct columns.
time longitude latitude
1 2012-10-28 23:01:00 16.42125 52.37832
2 2012-10-28 23:02:00 16.42125 52.37832
3 2012-10-28 23:03:00 16.42127 52.37832
...
For compatibility reasons, I store the time values instead of the row indices in some places. How can I obtain the (always consecutive) rows with those time values?
With indices, I’d do this:
indices <- 1:3
rows <- dat[indices,]
But with time:
times <- dat$time[1:3]
rows <- ???
What’s an efficient solution?
Switch to package xts. Here us a random example for you:
You can easily create
xtsobjects from existing ones, read from file, etc pp. Lots of examples here too.Now you can use the nice subsetting:
or even in shorthand: