Hello,
Try something along the lines of
res <- lapply(split(dat, list(dat$id, dat$trip)), function(x) x[x$time
== min(x$time), ])
do.call(rbind, res)
Note that 'data' is an R function, so I've called it 'dat'.
And that the column names are not exactly the same.
Also, you should follow the posting guide and post a data example using
dput(). Like this:
dput(head(dat, 20)) # or 30, see ?head
Then copy the output of that instruction and paste it in your post.
Hope this helps,
Rui Barradas
Em 08-06-2012 14:02, capital_P escreveu:> I'm fairly new to R and still learning how to use it. I could really
use some
> help with the following problem.
>
> I have a huge .csv file containing thousands of measurements on 34
different
> birds. Measurements include longitude,
latitude, altitude, speed, time, etc.> All birds have a different number (ranging from 121 to 542). All
> measurements have a tripID (1 for the first trip of every bird, 2 for the
> second, etc.)
>
> I need to create a vector containing only the first measurement of every
> trip. I need this to see at what time a bird leaves the nest and eventually
> make a histogram out of that.
>
> I need to write a piece of code that would look something like this:
>
> bird121trip1 <- (data[which(data$device_info_serial == 121 &
> [which(data$tripID == 1)] & [which(data$time == "lowest"),]
>
> bird121trip2 <- (data[which(data$device_info_serial == 121 &
> [which(data$tripID == 2)] & [which(data$time == "lowest"),]
>
> bird130trip1 <- (data[which(data$device_info_serial == 130 &
> [which(data$tripID == 1)] & [which(data$time == "lowest"),]
>
> etc.
>
> trip.departures <- c(bird121trip1, bird121trip2, bird130trip1, etc)
>
> I could do it like I described above (although I would have to replace
> "lowest" with something that actually works), but I have 34 birds
and many
> of them have hundreds of different trips. I'm sure there's an
easier and
> faster way to do that.
>
> Any help would be greatly appreciated. Thanks in advance.
>
> --
> View this message in context:
http://r.789695.n4.nabble.com/noob-requesting-help-tp4632803.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>