[R] filtering data by the time stamp
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Wed Jun 22 06:07:17 CEST 2016
This is normal. R is a (mostly) functional language, which means functions normally don't have side effects like changing input data.
Try saving the result of your function calls in a new object.
--
Sent from my phone. Please excuse my brevity.
On June 21, 2016 3:57:54 PM PDT, Alice Domalik <9add2 at queensu.ca> wrote:
>Hi List,
>
>
>I'm working with some bird GPS tracking data, and I would like to
>exclude points based on the time stamp.
>
>Some background information- the GPS loggers track each bird for just
>over 24 hours, starting in the evening, and continuing through the
>night and the following day. What I would like to do is exclude points
>taken after 21:30 on the day AFTER deployment (but retain points
>between 21:30 and 23:59 on the day of deployment).
>
>My data is set up like this:
>
>birdID x y datetime
>15K11 492719.9 5634805 2015-06-23 18:25:00
>
>I've tried running the code posted below.
>The idea is to use the function "mutate" to create a new variable
>called newdate that takes the earliest observation for each bird and
>sets the date for cutoff as the next day at 21:30:00.
>
>library(dplyr); library(lubridate)
>
>df %>%
> group_by(birdID) %>%
>mutate(newdate=as.POSIXct(date(min(datetime)) + days(1) + hours(21) +
>minutes(30))) %>%
> filter(datetime<newdate)
>
>R runs the code, but it doesn't actually change the data frame. I've
>double checked that "datetime" is POSIXct. I've also tried running the
>code without the the last line to check if R will at least create the
>new column "newdate", but it doesn't.
>Any insight into why my code isn't working?
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.
More information about the R-help
mailing list