Is there a way to map to any type with purrr::map
library(tidyverse)
library(lubridate)
df <- data_frame(id = c(1, 1, 1, 2, 2, 2),
val = c(1, 2, 3, 1, 2, 3),
date = ymd("2017-01-01") + days(1:6))
df1 <- df %>% nest(-id) %>%
mutate(first_val = map_dbl(data, ~ .$val[1]),
first_day = map(data, ~ .$date[1]))
I would like first_day
to be a column of type <date>
as in df
. I have tried flatten
, but this does not work as it coerces the column to numeric.