3
If I have a date.frame formed by the vectors:
V1<-c("A","B","C","D","B")
V2<-c("C","D","C","B","B")
V3<-c("D","D","C","A","A")
V4<-c("C","B","C","A","C")
G1<-c("C","C","A","A","B")
G2<-c("D","B","D","C","A")
G3<-c("A","B","B","C","A")
G4<-c("C","C","B","A","D")
dd<-data.frame(V1,V2,V3,V4,G1,G2,G3,G4)
V1 V2 V3 V4 G1 G2 G3 G4
A B B A A D B C
B C A C B C A C
B D D C D A D D
C C B C D A D C
C B C D B B C A
I wanted to create 4 new columns with names R1,R2,R3,R4 that see if V1=G1, V2=G2 and so on, and take information 1 for true and 0 for false
I had it so, but I wanted a command to do them all at once.
dd$R1<-ifelse(dd$V1 == dd$G1, 1,0)
I tried to use it for but it wasn’t working.