You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brief description of the problem: pivot_wider throws a strange error when used with a value_from column of type <Period> (as output from lubridate).
I am using R-3.6.3, lubridate_1.7.4, dbplyr_1.4.2.
Reprex:
df_0<- tibble(period_name= c("a", "b", "c"),
period_value= c("1:1:1",
"2:2:2",
"4:4:4")) %>%
mutate(period_value=lubridate::hms(period_value))
df_0## A tibble: 3 x 2# period_name period_value# <chr> <Period>#1 a 1H 1M 1S#2 b 2H 2M 2S#3 c 4H 4M 4S
Now, let's try widening the data frame
df_0 %>% pivot_wider(names_from=period_name, values_from=period_value)
#Error: No common type for `value` <Period> and `x` <Period>.
This error does not make sense to me.
BTW, at least it throws an error, whereas spread silently messed it up (see Stackoverflow question).
It works fine, though, with date_time type:
df_1<- tibble(dttm_name= c("a", "b", "c"),
dttm_value= c("2020-01-01 1:1:1",
"2020-02-03 2:2:2",
"2020-05-10 4:4:4")) %>%
mutate(dttm_value=lubridate::as_datetime(dttm_value))
df_1## A tibble: 3 x 2# dttm_name dttm_value# <chr> <dttm>#1 a 2020-01-01 01:01:01#2 b 2020-02-03 02:02:02#3 c 2020-05-10 04:04:04df_1 %>% pivot_wider(names_from=dttm_name, values_from=dttm_value)
## A tibble: 1 x 3# a b c# <dttm> <dttm> <dttm>#1 2020-01-01 01:01:01 2020-02-03 02:02:02 2020-05-10 04:04:04
Is that something wrong with pivot_wider (and spread) or with lubridate's Period class?
The text was updated successfully, but these errors were encountered:
Brief description of the problem:
pivot_wider
throws a strange error when used with a value_from column of type<Period>
(as output from lubridate).I am using R-3.6.3, lubridate_1.7.4, dbplyr_1.4.2.
Reprex:
Now, let's try widening the data frame
This error does not make sense to me.
BTW, at least it throws an error, whereas
spread
silently messed it up (see Stackoverflow question).It works fine, though, with date_time type:
Is that something wrong with
pivot_wider
(andspread
) or with lubridate'sPeriod
class?The text was updated successfully, but these errors were encountered: