Hi, I have two data frames with the same ID keys at T1 and T2. What is the best way to trim down both data frames such that all ID's are removed that are NA in either data frame?
This is what I came up with but it seems kind of clunky.
library(dplyr)
# two data frames at t1 and t2
t1 <- data.frame(id = c(1,2,3,4,5,6,7),
y = c(100,NA,300,400,NA,600,700))
t2 <- data.frame(id = c(1,2,3,4,5,6,7),
y = c(NA,200,300,NA,500,600,700))
# remove ID's with NA's at t1 OR t2
tcombined <- cbind(t1,t2) %>% na.omit()
# go back to respective data frames
t1 <- tcombined[,1:2]
t2 <- tcombined[,3:4]
Appreciate any thoughts.