Reputation: 491
I am trying to use lubridate
package along with the select function and piping provided in the tidyverse
package for viewing the days in the dates. However, I cannot get it to work while using select. I thought I could use select
instead of using the $
operator. What is the problem here?
library(tidyverse)
library(lubridate)
> df <- data.frame(arrivals = c("2015-11-11","2015-11-12"))
> df$arrivals %>% day()
[1] 11 12
> df %>% select(arrivals) %>% day()
Error in as.POSIXlt.default(x, tz = tz(x)) :
do not know how to convert 'x' to class “POSIXlt”
Upvotes: 0
Views: 1043
Reputation: 1139
df$arrivals
returns a vector whilst df %>% select(arrivals)
returns a data.frame which lubridate
apparently can't work with.
Using the mutate
function instead gives the following:
> df %>% mutate(day(arrivals))
arrivals day(arrivals)
1 2015-11-11 11
2 2015-11-12 12
Upvotes: 2