R 添加序列号重复序列的列
我想在15000行以上的数据帧中添加一个重复数字1到577的列 这是数据帧:R 添加序列号重复序列的列,r,dataframe,sequence,tibble,R,Dataframe,Sequence,Tibble,我想在15000行以上的数据帧中添加一个重复数字1到577的列 这是数据帧: > head(corr_dat_cond1) participant search_difficulty key_resp.corr key_resp.rt target_position distractor1_colour 1 1010 difficult 1 1.0820000 left [0.82,0.31,0]
> head(corr_dat_cond1)
participant search_difficulty key_resp.corr key_resp.rt target_position distractor1_colour
1 1010 difficult 1 1.0820000 left [0.82,0.31,0]
2 1010 no_search 1 0.5400000 left [-1,-1,-1]
3 1010 difficult 1 0.5119998 down [0.82,0,0.31]
4 1010 no_search 1 0.7079999 right [-1,-1,-1]
5 1010 difficult 1 1.0249999 up [0.82,0.31,0]
6 1010 no_search 1 0.4889998 left [-1,-1,-1]
distractor2_colour non_target_colour non_target_pos cue_uposition target_char non_target_char cue_time
1 [0.82,0,0.31] [0.82,0.31,0] [0.328,0] up = x 1.1
2 [-1,-1,-1] [-1,-1,-1] [0.328,0] right x = 1.2
3 [0.82,0.31,0] [0.82,0,0.31] [0.328,0] down x = 1.0
4 [-1,-1,-1] [-1,-1,-1] [0,0.328] left = x 1.4
5 [0.82,0,0.31] [0.82,0.31,0] [0,-0.328] left x = 1.4
6 [-1,-1,-1] [-1,-1,-1] [0,-0.328] up x = 1.0
cue_colour n cue_validity mrt stdev low_cutoff high_cutoff cond trial_num
1 Mismatch (Onset) cue 577 FALSE 0.7639095 0.2481090 0.0195825 1.5082365 1 1
2 Mismatch (Onset) cue 577 FALSE 0.5530880 0.1243826 0.1799402 0.9262358 1 2
3 Mismatch (Onset) cue 577 TRUE 0.7639095 0.2481090 0.0195825 1.5082365 1 3
4 Match (Color) cue 577 FALSE 0.5530880 0.1243826 0.1799402 0.9262358 1 4
5 Match (Color) cue 577 FALSE 0.7639095 0.2481090 0.0195825 1.5082365 1 5
6 Mismatch (Onset) cue 577 FALSE 0.5530880 0.1243826 0.1799402 0.9262358 1 6
trial_num列是我尝试添加序列号列的第一次尝试。这是我使用的代码:
corr_dat_cond1$trial_num <- 1:nrow(corr_dat_cond1)
corr\u dat\u cond1$trial\u num您可以使用rep\u len
功能
trial_num <- rep_len(1:577, nrow(corr_dat_cond1))
trial\u num Tryrep(1:577,length.out=nrow(corr\u dat\u cond1))
在给出ID之前使用“group\u by()”