问题
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