test1 <- data.frame(ID=1:10,
KEEP=c("First","Last","Both","Both","Both",
"Both","First","Neither","Last","Both"),
V1=c("a","a","a","B","b","B","A","A","A","a"),
V2=c("a","a","A","B","B","b","A","A","A","a"))
keepFirst <- repeatedRows2Keep(test1,cols2ignore=1:2)
keepLast <- repeatedRows2Keep(test1,cols2use=3:4,keep="last")
data.frame(test1,keepFirst,keepLast)
droplevels(subset(test1,keepFirst)) # should be all "First" or "Both" (7 items)
droplevels(subset(test1,keepLast)) # should be all "Last" or "Both" (7 items)
Run the code above in your browser using DataLab