我在R工作,如果可能的话,我更喜欢dplyr解决方案.
sample data:个
data.frame(
col1 = c("a", "b", "c", "d"),
col2 = c("a", "b", "d", "a"),
col3 = rep("a", 4L),
col4 = c("a", "b", "d", "a"),
col5 = c("a", "a", "c", "d"),
col6 = rep(c("b", "a"), each = 2L)
)
col1 | col2 | col3 | col4 | col5 | col6 |
---|---|---|---|---|---|
a | a | a | a | a | b |
b | b | a | b | a | b |
c | d | a | d | c | a |
d | a | a | a | d | a |
Question个
我想知道每一行,col1,、col2和col3是否与col4, col5和col6,相同,但COL1-COL3和COL4-COL6的顺序应忽略不计.
因此,对于第1行,如果col 1-col 3分别包含a、a、b,col 4-col 6分别包含b、a、a,那么这将被视为匹配.
Desired result个
我在"判断"栏目中注明,以帮助理解
col1 | col2 | col3 | col4 | col5 | col6 | assessment |
---|---|---|---|---|---|---|
a | a | a | a | a | b | FALSE (because 1-3 are not same as 4-6) |
b | b | a | b | a | b | TRUE (because 1-3 are the same as 4-6, if ignore order) |
c | d | a | d | c | a | TRUE (because 1-3 are the same as 4-6, if ignore order) |
d | a | a | a | d | a | TRUE (because 1-3 are the same as 4-6, if ignore order) |