根据单独数据框中的值删除行

时间:2020-10-07 23:39:53

标签: r dataframe indexing filter merge

我有一个名为corr_dat_cond1的数据框,该数据框具有试验任务的试用版。

    > head(corr_dat_cond1)
  participant search_difficulty key_resp.corr key_resp.rt target_position distractor1_colour distractor2_colour non_target_colour
1        1010              easy             1   1.1869998           right          [0,0.5,1]          [0,0.5,1]        [0,0.59,0]
2        1010         difficult             1   1.2490001            down      [0.82,0.31,0]      [0.82,0,0.31]     [0.82,0.31,0]
3        1010              easy             1   1.0100000              up          [0,0.5,1]         [0,0.59,0]        [0,0.59,0]
4        1010              easy             1   0.8659999            down          [0,0.5,1]          [0,0.5,1]        [0,0.59,0]
5        1010         no_search             1   0.8559999           right         [-1,-1,-1]         [-1,-1,-1]        [-1,-1,-1]
6        1010              easy             1   0.6269999           right          [0,0.5,1]         [0,0.59,0]        [0,0.59,0]
  non_target_pos cue_uposition target_char non_target_char cue_time           cue_colour cue_validity
1     [0,-0.328]            up           x               =      1.4 Mismatch (Onset) cue        FALSE
2      [0,0.328]          left           x               =      1.0 Mismatch (Onset) cue        FALSE
3      [0.328,0]          down           x               =      1.1 Mismatch (Onset) cue        FALSE
4      [0.328,0]         right           =               x      1.4    Match (Color) cue        FALSE
5     [-0.328,0]          down           =               x      1.4 Mismatch (Onset) cue        FALSE
6     [0,-0.328]         right           =               x      1.4    Match (Color) cue         TRUE

我的第二个数据帧是cond1_participant_meanrts,它对每个search_difficulty级别的每个参与者都具有high_cutoff和low_cutoff。

    > head(cond1_participant_meanrts)
# A tibble: 6 x 6
# Groups:   participant [2]
  participant search_difficulty   mrt stdev low_cutoff high_cutoff
        <dbl> <chr>             <dbl> <dbl>      <dbl>       <dbl>
1         636 difficult         1.10  0.224     0.426         1.77
2         636 easy              0.986 0.270     0.177         1.79
3         636 no_search         0.909 0.298     0.0160        1.80
4         642 difficult         1.02  0.268     0.221         1.83
5         642 easy              0.887 0.237     0.175         1.60
6         642 no_search         0.809 0.225     0.135         1.48

如果key_resp.rt值大于cond1_participant_meanrts中对应的(基于参与者和search_difficulty)high_cutoff值,或者key_resp.rt值小于cond1_particips_meanrts中对应的low_cutoff值,我想删除corr_dat_cond1中的行。 / p>

有没有办法做到这一点?预先感谢。

1 个答案:

答案 0 :(得分:0)

这是您需要的吗?

// Example program
#include <iostream>
#include <string>

template<typename T = void>
struct Foo
{       
    struct Bar
    {
        std::uint32_t x = -1;
    
        constexpr Bar(std::uint32_t x) : x(x) {}
    };
    
    static constexpr Bar CONST_BAR = Bar(0);
};

int main()
{
    std::cout << "x: " << Foo<>::CONST_BAR.x << "\n";
}