There's probably a good reason for this, but I'm pretty new to R and it's beyond me!
I have a data frame with two datetime columns, start and end.
I was able to build a mutate chain to extract various bits as such:
started <- cyc_trips$started_at ended <- cyc_trips$ended_at cyc_trips <- cyc_trips %>% mutate( started_date = as.Date (started), started_day = wday(started, label = TRUE), started_month = month(started, label = TRUE), started_time = as_hms(started), started_hour = hour(started), started_min = minute(started), ended_time = as_hms(ended), ended_hour = hour(ended), ended_min = minute(ended), trip_dur_sec = duration(as.numeric(ended - started)) )
When I add the line below to the chain, I get an error and warning.
trip_dur_per = as.period(as.duration(interval(started, ended))) + )
Error in dimnames(x) <- dn : length of 'dimnames'  not equal to array extent In addition: Warning message: In cbind(ride_id = c("4CA9676997DAFFF6", "F3E84A230AF2D676", "A1F2C92308007968", : number of rows of result is not a multiple of vector length (arg 1)
And yet, it works just fine when I create that column individually with the line below. I don't understand why there'd be a discrepancy in the vector length. I dropped all rows with NA and empty observations earlier so I don't suspect that to be the case.
cyc_trips$trip_dur_per <- as.period(as.duration(interval(started, ended)))
Can anyone explain what's going on? Thank you!