I have the following tibble:
data_frame(type = list( c('1','2', 'text'), c(1L ,2L), c(1.5, 2.1), c(TRUE, FALSE))) %>%
mutate(typeof=unlist(map(type, typeof)),
mode= unlist(map(type, mode)),
class= unlist(map(type, class)))
# A tibble: 4 x 4
type typeof mode class
<list> <chr> <chr> <chr>
1 <chr [3]> character character character
2 <int [2]> integer numeric integer
3 <dbl [2]> double numeric numeric
4 <lgl [2]> logical logical logical
and I want to add a column with the content of the column type, like:
# A tibble: 4 x 4
type typeof mode class vector
<list> <chr> <chr> <chr> <chr>
1 <chr [3]> character character character c('1','2', 'text')
2 <int [2]> integer numeric integer c(1L ,2L)
3 <dbl [2]> double numeric numeric c(1.5, 2.1)
4 <lgl [2]> logical logical logical c(TRUE, FALSE)
I tried unlist(map(type, quote))
but it gives:
# A tibble: 4 x 5
type typeof mode class vector
<list> <chr> <chr> <chr> <list>
1 <chr [3]> character character character <symbol>
2 <int [2]> integer numeric integer <symbol>
3 <dbl [2]> double numeric numeric <symbol>
4 <lgl [2]> logical logical logical <symbol>
Not even sure what <symbol>
is either...
First of all, if your are using the
purrr
package,unlist
is probably not necessary when creating the example data frame. We can usemap_chr
to get the same output.As for your desired output, I think we can use
map_chr
withtoString
to create a character string with all the contents in a list. Although it is still a little different than the output you want, I think it serves the demonstration purpose.