Archive for June, 2016

R managing duplicates

duplicated() – returns logical vector: TRUE if value appears in vector with lower index
given a vector of ids:
ids$dup = duplicated(ids)

add a “b” to the end of the duplicates
idstrans <- mapply(function(i,d) { if(d) { paste(i,”b”,sep = “”) } else { i } },ids$id,ids$dup)

Leave a Comment