Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

group_by %.% mutate does not preserve tzone for POSIXct #265

Closed
ateucher opened this issue Feb 14, 2014 · 0 comments
Closed

group_by %.% mutate does not preserve tzone for POSIXct #265

ateucher opened this issue Feb 14, 2014 · 0 comments

Comments

@ateucher
Copy link
Contributor

@ateucher ateucher commented Feb 14, 2014

This was fixed for summarise (#252), but still occurs with mutate (only on a grouped df). This is with the current development version of dplyr:

require(lubridate)
require(dplyr)

test.df <- structure(
  list(ID = c(rep(1,20),rep(2,20)),
       Date = structure(c(-247320000, -246196800, -245073600, -243864000,
                            -242654400, -241444800, -126273600, -123595200,
                            -121176000, -118497600, 1359385200, 1359388800,
                            1359392400, 1359396000, 1359399600, 1359403200,
                            1359406800, 1359410400, 1359414000, 1359417600,
                            55598400, 56116800, 58881600, 62078400, 64756800,
                            67348800, 69854400, 72964800, 76161600, 79012800,
                            1358589600, 1358676000, 1358762400, 1358848800,
                            1358935200, 1359021600, 1359108000, 1359194400,
                            1359280800, 1359367200), tzone = "GMT",
                          class = c("POSIXct", "POSIXt")),
       Val=rnorm(40)),
  .Names = c("ID", "Date", "Val"), row.names = c(NA, 40L),
  class = "data.frame")

out.df <- group_by(test.df, ID, fl_date=floor_date(Date, unit="month")) %.%
  mutate(length_x=n(), summary_date = 
           if (n() < 5) round_date(Date, "month") else floor_date(Date, "day"))

attr(out.df$summary_date, "tzone") # This is null

This works:

out2.df <-test.df %.% mutate(summary_date = round_date(Date, "month"))
attr(out2.df$summary_date, "tzone") # "GMT"

I left this as a comment in #252 after it was closed, so I thought it may have been lost - my apologies if it's already been captured.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant