在语料库“ tkn_pb”中,我想删除所有单词,除了我选择的某些关键字(例如,“ attack”和“ gunman”)。可以这样做吗?
您可以使用which和grepl作为tkn_pb的子集:
which
grepl
tkn_pb
数据:
tkn_pb <- c("word", "another","a", "new", "word token", "one", "more", "and", "another one")
删除除“ a”和“ and”以外的所有单词:
tkn_pb[which(grepl("\\b(a|and)\\b", tkn_pb))] [1] "a" "and"