我想基于执行的测试来对数据帧进行子集化。例如,我进行了测试
CheckUnsystematic(dat = long, deltaq = 0.025, bounce = 0.1, reversals = 0, ncons0 = 2)
它给了我这个:
> CheckUnsystematic(dat = long, deltaq = 0.025, bounce = 0.1, reversals = 0, ncons0 = 2)
> CheckUnsystematic(dat = long, deltaq = 0.025, bounce = 0.1, reversals = 0, ncons0 = 2)
id TotalPass DeltaQ DeltaQPass Bounce BouncePass Reversals ReversalsPass NumPosValues
1 2 3 0.9089 Pass 0.0000 Pass 0 Pass 15
2 3 3 0.6977 Pass 0.0000 Pass 0 Pass 16
3 4 2 0.0000 Fail 0.0000 Pass 0 Pass 18
4 5 3 0.2107 Pass 0.0000 Pass 0 Pass 18
5 6 3 0.2346 Pass 0.0000 Pass 0 Pass 18
6 7 3 0.9089 Pass 0.0000 Pass 0 Pass 16
7 8 3 0.9622 Pass 0.0000 Pass 0 Pass 15
8 9 3 0.8620 Pass 0.0000 Pass 0 Pass 11
9 10 3 0.9089 Pass 0.0000 Pass 0 Pass 12
10 11 3 0.9089 Pass 0.0000 Pass 0 Pass 11
我只想在“ TotalPass”中保留具有“ 3”的观测值。
我尝试了这个:
CleanAPT <- long[ which(long$TotalPass==3),]
答案 0 :(得分:0)
由于您确实将其标记为dplyr
问题,所以我们使用它:
library(dplyr)
check_df <- CheckUnsystematic(dat = long, deltaq = 0.025,
bounce = 0.1, reversals = 0, ncons0 = 2)
CleanAPT <- check_df %>%
filter(TotalPass == 3)
CleanAPT <- long[ which(long$TotalPass==3),]
不起作用的原因是因为您正在调用long
数据帧(未通过CheckUnsystematic
函数进行修改)。在上面,我将函数结果保存到check_df
。因此,CleanAPT <- check_df[which(check_df$TotalPass==3),]
应该可以工作。
重新合并原始数据(由于long
的列名很难说清楚,所以假设id
存在并且是唯一的)可以使用{{1} }来自semi_join
:
dplyr
答案 1 :(得分:0)
尝试使用较长的数据集。
th:utext="${sample.specialTry} ? '☑' : ''"