[R] Please help me subset this dataframe, thanks...

Mark Na mtb954 at gmail.com
Mon May 4 04:38:20 CEST 2009


Dear R-helpers,

I have a dataframe called "trackpoints" with several columns including
a column called "time", eg:

> trackpoints
        time
1   12:00:00
2   12:00:01
3   12:00:02
.
.
.
298 12:04:57
299 12:04:58
300 12:04:59

I also have a dataframe called "data" that contains columns called
"ID", "start" and "stop", eg:

> data
  ID    start     stop
1  1 12:00:00 12:01:30
2  2 12:02:16 12:03:01
3  3 12:03:58 12:04:31

I wish to make a dataframe called "extracted" containing only the rows
in "trackpoints" with a value of "time" bounded by the times in
data$start and data$stop and a column called "ID" containing the value
from data$ID, eg:

> extracted
        Time ID
1   12:00:00  1
2   12:00:01  1
3   12:00:02  1
.
.
.
89  12:01:28  1
90  12:01:29  1
91  12:01:30  1

I have the vague notion that I might have to loop this, but I think it
would be cleaner to use logical subscripts, if possible.
I'd appreciate any help you might be able to provide.

Thanks! Mark Na




More information about the R-help mailing list