Hi Stefan1,
Your suggestion really closed to the ways I want,
I did the following ways, but still need to improve
r <- lapply(dup$variable, strsplit, " ")
r <- lapply(r, unlist)
r
for (i in seq_along(r)) {
assign(paste0("r", i), r[[i]])
assign(paste0("d", i), df[ , r[[i]] ])
assign(paste0("dupid", i), df[duplicated("d",i) | duplicated("d",i, fromLast=TRUE),])
}
After running above, dupid1 and dupid2 have no observation,
However, I run this out of the loop, it works well
dupid1<- df[duplicated(d1) | duplicated(d1, fromLast=TRUE),]
I got 20 rows that have duplicated cases. Would you mind me to give away to improve in the loop to get a similar result like dupid1?