我有一个数据框values
,如下所示
row.names January February March
A1 0.02345 0.03456 0.04567
A2 0.07654 0.06543 0.05432
A3 0.02345 0.03456 0.04567
我需要提取列值大于前一列的行 我们可以看到,对于A1和A3,列值大于先前的值。即0.02345 <0.03456 <0.04567
row.names January February March
A1 0.02345 0.03456 0.04567
A3 0.02345 0.03456 0.04567
需要帮助来提取具有上述要求的行。
答案 0 :(得分:1)
这是一种可行的方法
indx <- colSums(apply(data, 1L, diff) > 0L) == (ncol(data) - 1L)
data[indx, ]
# January February March
# A1 0.02345 0.03456 0.04567
# A3 0.02345 0.03456 0.04567
更简单的版本(参见@alexis_laz评论)是使用内置的unsorted
函数
indx <- !apply(data, 1, is.unsorted)
data[indx, ]