我有以下df,其中df< - data.frame(V1 = c(0,0,1),V2 = c(0,0,2),V3 = c(-2,0,2) )
如果我过滤(df,rowSums!= 0),我会收到以下错误: filter_impl(.data,quo)中的错误: 评估错误:比较(6)仅适用于原子和列表类型。
有人知道为什么吗? 谢谢你的帮助
PS:普通 rowSums(df)!= 0 工作得很好,给了我预期的逻辑
答案 0 :(得分:1)
A more tidyverse
style approach to the problem is to make your data tidy, i.e., with only one data value.
my_mat <- matrix(sample(c(1, 0), replace=T, 60), nrow=30) %>% as.data.frame
group_by
my_mat %>%
mutate(row = row_number()) %>%
gather(col, val, -row) %>%
group_by(row) %>%
filter(sum(val) == 0)
This tidy approach is not always as fast as base R, and it isn't always appropriate for all data types.
答案 1 :(得分:0)
好的,我明白了。 滤波器(DF,rowSums(DF)!= 0)
不是最难的...... 感谢。