【发布时间】:2018-04-10 08:29:14
【问题描述】:
我见过使用gsub 和sapply 从数据框中删除单词的示例。
有没有使用purrr库中的map的解决方案
library(purrr)
ID<-c(1,2)
Text_W<-c("I love vegetables, and some fruits","Can we meet tomorrow for a movies, and other fun activities")
new_tab<-tibble(ID,Text_W)
remove_words<-c("love", "and")
我尝试了这些但没有成功:
#gsub from base
map_chr(new_tab$Text_W,~paste(gsub(remove_words,"")))
library(stringr)
#
map(new_tab$Text_W,~paste(str_replace_all(remove_words,"")))
任何帮助将不胜感激。
【问题讨论】:
标签: r lapply sapply stringr purrr