dplyr filter()忽略值为0的行,怎么改
dplyr filter () ignores the rows with the value 0, how to change that
在我的例子中,我需要过滤函数来考虑值为 0 的行,但它忽略了这一点。
所以我附上了这些数据,我想分别过滤掉 s1 和 s2 名称的花的值。我的 table 是 case1
s1= filter(case1, Flower,Name=="s1")
s2= filter(case1, Flower,Name=="s2")
这条语句运行良好,但它忽略了 0 值。我还想在我的分析中包含 0 值。那么,我该如何接受呢
在评论后编辑
Flower,Name,Pl
10, s1, WI
10, s1, WO
30, s1, EI
0, s1, EO
0, s2, EI
0, s2, EO
0, s1, WI
0, s2, WO
0, s2, WO
3, s2, WI
50, s2, EI
0, s1, EO
0, s1, EI
预期输出:
对于 s1,s1 的所有值都是这样的(包括 Flower 0 的行)
Flower, Name, Pl
10, s1, WI
10, s1, WO
30, s1, EI
0, s1, EO
对于 s2,s2 的所有值,诸如此类
Flower, Name, Pl
0, s2, WO
0, s2, WO
3, s2, WI
50, s2, EI
你可以做到
filter(case1, Name=='s1')
# Flower Name PI
#1 10 s1 WI
#2 10 s1 WO
#3 30 s1 EI
#4 0 s1 EO
#5 0 s1 WI
#6 0 s1 EO
#7 0 s1 EI
通过在 filter
中使用 'Flower','0' 值被强制为 'FALSE' 和所有其他 'TRUE'.
在我的例子中,我需要过滤函数来考虑值为 0 的行,但它忽略了这一点。
所以我附上了这些数据,我想分别过滤掉 s1 和 s2 名称的花的值。我的 table 是 case1
s1= filter(case1, Flower,Name=="s1")
s2= filter(case1, Flower,Name=="s2")
这条语句运行良好,但它忽略了 0 值。我还想在我的分析中包含 0 值。那么,我该如何接受呢
在评论后编辑
Flower,Name,Pl
10, s1, WI
10, s1, WO
30, s1, EI
0, s1, EO
0, s2, EI
0, s2, EO
0, s1, WI
0, s2, WO
0, s2, WO
3, s2, WI
50, s2, EI
0, s1, EO
0, s1, EI
预期输出:
对于 s1,s1 的所有值都是这样的(包括 Flower 0 的行)
Flower, Name, Pl
10, s1, WI
10, s1, WO
30, s1, EI
0, s1, EO
对于 s2,s2 的所有值,诸如此类
Flower, Name, Pl
0, s2, WO
0, s2, WO
3, s2, WI
50, s2, EI
你可以做到
filter(case1, Name=='s1')
# Flower Name PI
#1 10 s1 WI
#2 10 s1 WO
#3 30 s1 EI
#4 0 s1 EO
#5 0 s1 WI
#6 0 s1 EO
#7 0 s1 EI
通过在 filter
中使用 'Flower','0' 值被强制为 'FALSE' 和所有其他 'TRUE'.