I am working with a dataset in R, and I have a problem that I can\'t seem to figure out. My data currently looks like this:
Team Person1 Person2 Pers
Yuo can identify duplicated person ids across the rows using apply
dat$dups <- apply(dat[-1], 1, function(i) any(duplicated(i[!is.na(i)])))
or as Simon O'Hanlon pointed out in the comments
dat$dups <- apply(dat[-1], 1, function(i) any(duplicated(i, incomparables = NA)))
You could then use this to either find the team numbers that have duplicates or to exclude them:
# Return teams that have duplicate person ids
dat$Team[ dat$dups ]
# Exclude rows with duplicates
dat[ ! dat$dups , ]