r - Match entire columns between two dataframes -
i have 2 dataframes
y <- data.frame(y1=seq(1:5), y2=letters[seq(1:5)]) x <- data.frame(x1=seq(1:5)*3,x2=seq(1:5), x3=letters[5:9], x4=letters[1:5]) and wat extract columns
x
that entirely match
y
columns.
does have clue?
thank you
we can loop , comparison
x[sapply(y, function(.y) which(colsums(x== as.character(.y))== nrow(y)))] or option is
i1 <- sapply(x, paste, collapse=",") %in% sapply(y, paste, collapse=",") i1 #[1] false true false true x[i1]
Comments
Post a Comment