[R] Loop for two columns and 154 rows
Hesham A. AL-bukhaiti
he@h@m|bb @end|ng |rom y@hoo@com
Tue Sep 15 11:01:13 CEST 2020
Dears in R :i have this code in R:
# this for do not work true (i tried )out<-read.csv("outbr.csv") truth<-out[,seq(1,2)]truth<-cbind(as.character(truth[,1]),as.character(truth[,2]) ,as.data.frame(rep(0,,dim(out)[1])));for (j in 1:2) { for (i in 1:20) { truth[(truth[,1]== truth[j,i] & truth[,2]== truth[j,i+1]) | (truth[,1]== truth[j+1,i] & truth[,2]== truth[j+1,i+1]),3]<-1 }
}
#truth<-out[,seq(1,2)]#truth<-cbind(as.character(truth[,1]),as.character(truth[,2]) # ,as.data.frame(rep(0,,dim(out)[1])));#truth[(truth[,1]=="G2" & truth[,2]=="G1") | (truth[,1]=="G1" & truth[,2]=="G2"),3]<-1
##########################################################################3
I have file have two columns . data in this file is text just (G1,G2,G3… to G154). one element can repeat, no problem ,so we have 23562 rows in two columns (for 154 elements) like :
Column1 column2 column3
G1 G4 0
G4 G6 0
G100 G7 1G7 G100 . 1. .. . I want to make third column (1 or 0) based on this condition:
IF truth[,1]==”G1” & truth[,2]==”G2” | truth[,1]==”G2” & truth[,2]==”G1” <-1.then In the third column write 1 otherwise write 0.G1 and G2 just exampl (indeed i want test If two each elements has a reciprocal relationship(G1 to G2 and G2 to G1or not)
Best regHesham
[[alternative HTML version deleted]]
More information about the R-help
mailing list