本文介绍了根据R中的单词列表过滤列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我想过滤> 200万行的数据集中的一列。如果该列中的任何行包含70个单词列表中的单词,则应进行过滤。 I would like to filter a column in a dataset with >2 million rows. The filtering should be done if any of the rows in that column contain words from a list of 70 words. 我用了这个 fruits $ type [grepl(c( apple, orange, grapes),fruits $ type)] 但出现以下错误:I used this fruits$type[grepl(c("apple","orange","grapes"),fruits$type)]But I get error as below:我尝试了建议此处,但不起作用。 谁能帮我吗?I tried suggestion mentioned here but not working.Could anyone please help me?推荐答案如果有很多关键词,我们可以遍历单词 grepl 并与 Reduce 和 | 一起获得单个逻辑矢量子集数据集If there are many key words, we can loop through the words do the grepl and with Reduce and | get a single logical vector to subset the datasetres <- fruits$type[Reduce(`|`, lapply(v1, grepl, x = fruits$type))]length(res)#[1] 11 数据 datav1 <- c("apple", "orange", "grapes")set.seed(24)fruits <- data.frame(type = sample(c("apple", "orange", "grapes", "banana", "water melon"), 20, replace=TRUE), val = rnorm(20), stringsAsFactors=FALSE) 这篇关于根据R中的单词列表过滤列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-18 17:22