Reputation: 3515
Still trying to get to grips with purrr
library(stringr)
library(purrr)
df <- data.frame(text=c("Even Flow", "My Sweet Lord"))
How can I use, presumably, map_chr and str_split to get, say, a vector of the second text elements i.e "Flow" "Sweet"
TIA
Upvotes: 3
Views: 1301
Reputation: 816
Here is a solution with data.table
library(stringr)
library(data.table)
df <- data.table(text=c("Even Flow", "My Sweet Lord"))
df[, text_second := tstrsplit(text, " ")[2]]
and using purrr
library(purrr)
df$text %>% map(str_split, pattern = " ") %>% map_chr(c(1,2))
Upvotes: 4