Hi,
I wonder how I can add a string such as _2
to every other row for the word
column. This means the second repetition of any word is coded by _2
stim word cog_id cog percent val label id position
1 abdul_mohd_3- su3uud cog_3 cog 01 774.9970 3 1 med
2 abdul_mohd_3- su3uud cog_3 cog 01 696.1061 3 2 med
3 abdul_mohd_f faatiH cog_f cog 01 720.3641 f 3 ini
4 abdul_mohd_f faatiH cog_f cog 01 704.4937 f 4 ini
5 abdul_mohd_T t-aamir cog_T cog 01 1004.3191 T 5 ini
6 abdul_mohd_T t-aamir cog_T cog 01 714.7134 T 6 ini
7 abdul_mohd_D d-aabil cog_D cog 01 864.7862 D 7 ini
8 abdul_mohd_D d-aabil cog_D cog 01 700.6315 D 8 ini
The output I am looking for is similar to this.
stim word cog_id cog percent val label id position
1 abdul_mohd_3- su3uud cog_3 cog 01 774.9970 3 1 med
2 abdul_mohd_3- su3uud_2 cog_3 cog 01 696.1061 3 2 med
3 abdul_mohd_f faatiH cog_f cog 01 720.3641 f 3 ini
4 abdul_mohd_f faatiH_2 cog_f cog 01 704.4937 f 4 ini
5 abdul_mohd_T t-aamir cog_T cog 01 1004.3191 T 5 ini
6 abdul_mohd_T t-aamir_2 cog_T cog 01 714.7134 T 6 ini
7 abdul_mohd_D d-aabil cog_D cog 01 864.7862 D 7 ini
8 abdul_mohd_D d-aabil_2 cog_D cog 01 700.6315 D 8 ini
This is the data:
data <- structure(list(stim = c("abdul_mohd_3-", "abdul_mohd_3-", "abdul_mohd_f",
"abdul_mohd_f", "abdul_mohd_T", "abdul_mohd_T", "abdul_mohd_D",
"abdul_mohd_D"), word = c("su3uud", "su3uud", "faatiH", "faatiH",
"t-aamir", "t-aamir", "d-aabil", "d-aabil"), cog_id = c("cog_3",
"cog_3", "cog_f", "cog_f", "cog_T", "cog_T", "cog_D", "cog_D"
), cog = c("cog", "cog", "cog", "cog", "cog", "cog", "cog", "cog"
), percent = c("01", "01", "01", "01", "01", "01", "01", "01"
), val = c(774.997032242575, 696.106140426446, 720.364098722029,
704.493709576387, 1004.31906059123, 714.713358502878, 864.786221065522,
700.631478305007), label = c("3", "3", "f", "f", "T", "T", "D",
"D"), id = 1:8, position = c("med", "med", "ini", "ini", "ini",
"ini", "ini", "ini")), row.names = c(NA, 8L), class = "data.frame")
Thank you for your time and help in advance!