I have a data.frame like data
. In the column named value
same values appears more than once (in more than one rows). I would like to match the rows that have the same value, in order to find their ids. In other words, I would like to have as a result that ids "P1","P3" and "P4" have the same value wich equals to 24.7386760 and the ids "P2"and "P6" has the same value that equals to 21.9178082.
I have used duplicated
function to spot the duplicated values and then filter
function to keep the rows with an exact value. I have tried this code:
id <- c("P1", "P2", "P3", "P4", "P5", "P6")
value <- c(24.7386760, 21.9178082, 24.7386760, 24.7386760, 20.7441860, 21.9178082)
data <- as.data.frame(cbind(id,value))
duplicates <- data$value[duplicated(data$value) | duplicated(data$value, fromLast=TRUE)]
View(duplicates)
library(dplyr)
cat1 <- filter(data,data$value == 24.7386760)
cat2 <- filter(data,data$value == 21.9178082)
Even though it can work for a small amount of different values it can not work for a lot of values, like my real problem values.
Any ideas on this? Thank you