I have the following data which looks like:
# A tibble: 6 × 2
`Total_ Española_Porcentaje` `Total_ Extranjero_Porcentaje`
<list> <list>
1 <dbl [3]> <dbl [3]>
2 <dbl [3]> <dbl [3]>
3 <dbl [3]> <dbl [3]>
4 <dbl [3]> <dbl [3]>
5 <dbl [3]> <dbl [3]>
6 <dbl [3]> <dbl [3]>
I am trying to map over the columns using map and extract the first dbl.
I have tried
df %>%
map_dbl(., ~if(length(.x)) .x[1] else NA)
and
df %>%
imap_dfc(., function(x, y)
tibble(!!y := map_dbl(x, ~if(length(.x)) .x[1] else NA)))
But I can't get it to work.
Data <- structure(list(`Total_ Española_Porcentaje` = list(c(5.9, 5.9,
5.9), c(5.9, 5.9, 5.9), c(5.9, 5.9, 5.9), c(5.9, 5.9, 5.9), c(5.9,
5.9, 5.9), c(5.9, 5.9, 5.9)), `Total_ Extranjero_Porcentaje` = list(
c(5.9, 5.9, 5.9), c(5.9, 5.9, 5.9), c(5.9, 5.9, 5.9), c(5.9,
5.9, 5.9), c(5.9, 5.9, 5.9), c(5.9, 5.9, 5.9))), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))