mercredi 15 avril 2020

Iterate through rows, look for matching characters with matching indexes, and if this is true: put a '1' in another column - R

I want to loop through 'standard' & 'superficial.match' and get two bits of additional data:

1) does 'standard' have a character that shares the same value and same index as a character in 'superficial.match' ('mips' = matching in place)

2) how many characters in 'standard' match with characters in 'superficial.match' ('two.match')

for example:

in row 1, there is a matching 4 in the third-place, and there are two 4's in 'standard' so 'mips' and '2match' should = True or 1

in row 6, 4 matches in place, but there is only 1 match, so 'mips' = True and 'two.match' = False

> head.matrix(masterdata[c(5,6,14,15)], n=6)
  standard superficial.match mips two.match
1      464               584    0      0
2      575               159    0      0
3      686               896    0      0
4      131               971    0      0
5      818               348    0      0
6      242               348    0      0

row 3 seems to have 1 character that matches in place and 1 that does not, this should be an 'NA' for 'mips'

Aucun commentaire:

Enregistrer un commentaire