I am (obviously) new to r, I want to evaluate a dataframe so that for every value that is the same in "id", I determine if there is a match for that same id for coder1 and coder2. Everything I've tried takes the first value encountered for each column, so I'm miss some matches where the id value is the same, but sometimes the coder1 and coder2 matching values occur on different rows. I need to find matches for all cases when the id is the same, regardless of what rows matching values are for coder1 and coder2 (as long as the id is the same)
The code I've included here works, I'd just have to create new dataframes for every id.
df1 <- df %>%
select(id, coder1,coder2) %>%
filter(id == 1)
df1$match <- df1$coder1 %in% df1$coder2
df2 <- df %>%
select(id, coder1,coder2) %>%
filter(id == 2)
df2$match <- df2$coder1 %in% df2$coder2
df3 <- df %>%
select(id, coder1,coder2) %>%
filter(id == 3)
df3$match <- df3$coder1 %in% df3$coder2
I'd like to end up with something like "output' (or with 1s and 0s instead of TRUE, FALSE)
output <- data.frame(
id = c(1L,1L,1L,1L,1L,2L,2L,2L,2L,2L,2L,
2L,2L,2L,2L,3L,3L),
coder1 = c(10L,20L,10L,10L,10L,20L,90L,90L,90L,
90L,10L,10L,10L,10L,10L,90L,20L),
coder2 = c(20L,10L,20L,20L,20L,30L,20L,20L,20L,
20L,30L,20L,20L,20L,20L,30L,30L),
match = c(TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE))
I apologize if this question has been asked before, I have reviewed so many posts, I'm still not able to figure this out. Thank you!