I have two datasets containing pre and post data. Respondents have unique identifiers, and I want to create a subset that includes only those who answered both polls. Dataset example:
pre.data <- data.frame(ID = c(1:10), Y = sample(c("yes", "no"), 10, replace = TRUE), Survey = 1) post.data <- data.frame(ID = c(1:3,6:10), Y = sample(c("yes", "no"), 8, replace = TRUE), Survey = 2) all.data <- rbind(pre.data, post.data)
I have the following function:
match <- function(dat1, dat2, dat3){
I think there should be a better way than this function to do the same, but I canβt think how to do it. How I did it seems a bit messy. I mean, it works - it does what I want, but I cannot help but think that there is a better way.
My apologies if this has already been asked in a similar way, but I could not find it - in this case, please indicate me the corresponding answer.
source share