문제

I am trying to compare the columns in a data frame to a master list. I would like R to compare the values in each cell and output T if they match and F if they do not.

For example:

Master
m<-c(1,2,2,2,1)

Data
a<-c(1,2,2,2,2)
b<-c(1,1,1,1,1)
c<-c(1,1,2,2,2)
d<-cbind(a,b,c)

Result of comparing m to the columns in d
  a b c
1 T T T
2 T F F
3 T F T
4 T F T
5 F T F

How might I achieve a comparison with this sort of output?

Thank you in advance!

도움이 되었습니까?

해결책

simply :

d==m

         a     b     c
[1,]  TRUE  TRUE  TRUE
[2,]  TRUE FALSE FALSE
[3,]  TRUE FALSE  TRUE
[4,]  TRUE FALSE  TRUE
[5,] FALSE  TRUE FALSE
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top