dat <- DATA
## Add a nested/list text column
dat$split <- lapply(dat$state, function(x) {
unlist(strsplit(x, '(?<=[?!.])\\s+', perl = TRUE))
})
unnest_text(dat)
unnest_text(dat, integer.rownames = FALSE)
## Add a second nested integer column
dat$d <- lapply(dat$split, nchar)
if (FALSE) {
unnest_text(dat) # causes error, must supply column explicitly
}
unnest_text(dat, 'split')
## As a data.table
library(data.table)
dt_dat <- data.table::as.data.table(data.table::copy(dat))
unnest_text(dt_dat, 'split')
if (FALSE) {
unnest_text(dt_dat, 'd')
}
if (FALSE) {
## As a tibble
library(tibble)
t_dat <- tibble:::as_tibble(dat)
unnest_text(t_dat, 'split')
}
Run the code above in your browser using DataLab