I have the following dataframe:
dframe <- structure(list(y = c(-0.551803287760631, -1.30494019324738, 0.00821236626893252,
0.638916511414093, -0.816805971651003, 1.12037288852287), Reg_Date = structure(c(1420217760,
1420217760, 1420217880, 1420217880, 1420217880, 1420217880), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), Del_Date = structure(c(NA, NA, 1468065900,
1468065900, 1468065900, 1468065900), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), days = c(1042L, 1042L, 554L, 554L, 554L, 554L
), Start_Date = structure(c(1420217880, 1420217880, 1420218180,
1420218180, 1420218180, 1420218180), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), Stop_Date = structure(c(NA, NA, 1468065900,
1468065900, 1468065900, 1468065900), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), group = c("A", "B", "C", "D", "E", "F")), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"), .Names = c("y",
"Reg_Date", "Del_Date", "days", "Start_Date", "Stop_Date", "group"
))
I would like to change the format
of all dates, and I try
> dframe %>% mutate_at(ends_with("Date"), format, usetz = TRUE)
Error: Variable context not set
What does this error mean? According to ?mutate_at
,
summarise_at(), mutate_at() and transmute_at() allow you to select columns using the same name-based select_helpers just like with select().
The problem is not due to format
, because using another function I get the same error:
> dframe %>% mutate_at(ends_with("Date"), as.character)
Error: Variable context not set
Can you help me? In my real use case I have much more Date
columns (and even more non-Date
columns), so having to select them by name is a real hassle. Sure, I could grep
in names(dframe)
, but, unless you think that base R is more appropriate in this case, I'd rather see a simple, readable dplyr
solution. Thanks!