仍然试图掌握purrr
library(stringr)
library(purrr)
df <- data.frame(text=c("Even Flow", "My Sweet Lord"))
我怎么能用map_chr和str_split来得到第二个文本元素的向量,即&#34; Flow&#34; &#34;甜&#34;
TIA
答案 0 :(得分:4)
以下是data.table
library(stringr)
library(data.table)
df <- data.table(text=c("Even Flow", "My Sweet Lord"))
df[, text_second := tstrsplit(text, " ")[2]]
并使用purrr
library(purrr)
df$text %>% map(str_split, pattern = " ") %>% map_chr(c(1,2))