This has been racking my brain! I have a dataframe with one column that contains duplicate values and another that does not contain duplicates, however any of these corresponding values are valuable to keep when selecting unique values in the first column. For example:
data <- data.frame(a = c(2,4,4,6,3,6,4,3,3,2,2), b = c("a", "b", "c", "a", "f", "e", "p", "e", "u", "c", "f"))
If I do something like:
res <- unique(data[c("a", "b")])
The result has to produce unique values in column a
, but b
can choose any of the corresponding values of the unique value to keep or discard.
The result has to do something like this:
res <- data.frame(a = c(2,4,6,3), b = c("a", "b", "a", "f"))
Any help would be appreciated!