How to filter meta data by user-defined statements in R?

一曲冷凌霜 提交于 2019-12-13 01:27:05

问题


There is a function called sFilter in R to filter meta data. However, the function is an old (Version: 0.5-10) tm package. Is there any function instead of it in a new version?

My code block is;

query <- "LEWISSPLIT == 'TRAIN'"
trainData <- tm_filter(Corpus, FUN = sFilter, query)

It means, get documents which have "TRAIN" value in their LEWISSPLIT attribute.

<REUTERS TOPICS=?? LEWISSPLIT=?? CGISPLIT=?? OLDID=?? NEWID=??>

回答1:


Just write your own filtering function:

trainData <- tm_filter(Corpus, FUN = function(x, qry) any(meta(x)["lewissplit"] == qry), "TRAIN")

This was adapted from example(tm_filter). There is an example using grep() for more flexible search.



来源:https://stackoverflow.com/questions/34399093/how-to-filter-meta-data-by-user-defined-statements-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!