I have a data set (Trails) with three columns, Group (column 1), First Name (column 2) and Last Name (column 3). I am trying to get a length of name matches between pairs of groups based on the first and last name. I have been using this:
#Counting the number of matches with both first and last name
*'''''shared<-length(intersect(GroupOne[2:3,], GroupTwo[2:3,]))'''''''*
However, some first names do not have a last name (=NA). So for first names that do not have a last name, I want to only match the first name or:
#match only the first name
*'''''shared<-length(intersect(GroupOne[2,], GroupTwo[2,]))'''''''*
And I want to do the same thing when there is no first name, just match the last name. I was trying to do this with if statements but keep getting errors or warning messages like this:
the condition has length > 1 and only the first element will be used
if (Trials$Last=="NA"){ paste(length(intersect(One[2,], Two[2,]))) }else if(Trials$First=="Na") { paste(length(intersect(One[3,], Two[3,]))) }else {length(intersect(One[2:3,], Two[2:3,])) }
I would greatly appreciate any guidance. Thank you.
Aucun commentaire:
Enregistrer un commentaire