【发布时间】:2016-10-22 03:31:45
【问题描述】:
我有一个我需要从中读取的 CSV 文件列表,其中包含多个文件,其中包含标题、描述...等列。从多个文件的这些列中,必须编写检索操作并与另一个 CSV 相匹配,该 CSV 由类似于 WordStream SEO 的工具生成的流行关键字(~10k)生成。
我能做什么
#Not sure if this is correct approach
Source1<- read.csv(path to csv file)
Keywords_tomatch<- read.csv(path to csv file)
#cant really take both the columns into single vector and iterate over them
subColdesc <- Source1[,c(3)]
subcolTitle <-Source1[,c(2)]
keywordget<- subset(Keywords_tomatch,grepl("*",Keywords_tomatch$col1))
#Two individual vectors since i'm not sure whether sapply() can be applied over multiple lists Definition: sapply(list,function)
descBoolean <- sapply(keywordget,
function(y)
sapply(subColdesc ,
function(x)
any(grepl(y,x)))
)
TitleBoolean = sapply(keywordget,
function(y)
sapply(subcolTitle ,
function(x)
any(grepl(y,x)))
)
#matches just the first element in the column of keywordget against (~4k) elements in description,title column. i.e returns a warning/error
在 grepl(y, x) 中: 参数“模式”的长度 > 1,并且只使用第一个元素
我已经在 Akrun's version of grep 尝试过,但它对我不起作用
问题:
如何匹配keywordget向量中的所有元素,检索Description,Title每一行匹配了哪些列,Description和Title匹配了哪些行。
简而言之,如何使用Keywords_tomatch检索Source1中所有游戏相关产品?
作为示例,我发布了我收集的两个文件。 Source1 只包含几行 4k 行
来源1 =1.csv, Keywords_tomatch = Gaming.csv
【问题讨论】:
标签: r pattern-matching