【发布时间】:2011-09-29 23:10:13
【问题描述】:
我确定我有一个非常基本的问题,但是在寻找有关如何完成某些数据框/矩阵的子集(获取行号)的想法后,我感到很沮丧,这些数据框/矩阵可以有任意数量的列,并且列名会更改所有时间。我只想查找数据框中任何列大于 0 的行(索引)。由于列名和列数未知,我不知道该怎么做...
一个例子:
# these are the terms I am looking in
terms <- c("beats", "revs", "revenue", "earnings")
# dict <- Dictionary(terms)
# dictStudy <- inspect(DocumentTermMatrix(mydata.corpus.tmp, list(dictionary = dict)))
dictStudy <- data.frame(beats=c(0, 0, 0, 1, 0, 2), revs=c(0, 0, 0, 1, 0, 1), revenue=c(0, 0, 0, 0, 0, 0), earnings=c(1, 0, 0, 1, 0, 1))
ss <- expression(terms > 0)
dictStudy.matching <- subset(dictStudy, eval(ss))
我希望表达式和 eval 能救我,但我想不通。
如何在数据框中仅查找任何列 > 0 的行?
【问题讨论】:
标签: r