Hi Hesham, It think you are looking for something like this: truth<-data.frame(G1=sample(LETTERS[1:4],20,TRUE), G2=sample(LETTERS[1:4],20,TRUE)) truth truth$G3<-as.numeric(truth$G1 == truth$G2) truth
Note that like quite a few emails produced with Javascript formatting, there are embedded characters that R can't interpret. Jim On Thu, Sep 3, 2020 at 11:18 AM Hesham A. AL-bukhaiti via R-help <r-help@r-project.org> wrote: > > hello.I have this code :#################################3#read data just > thee columns. first and second columns are catogary , third column is > number. out<-read.csv("outbr.csv") > truth<-out[,seq(1,2)] #truth about 2000 rows, some values in row1 can show > in rows2,and the some values in row2 can also show in row1 : > #for example :#G1(row1), G2(row2) > #G2(row1),G1(row2) > #if this happend add to thrid column in truth 1 otherwise add 0 as in > statment followtruth<-cbind(as.character(truth[,1]),as.character(truth[,2]) > ,as.data.frame(rep(0,,dim(out)[1])));#here just G2 and G3, i want > make loop to cam[are all values from G1 to G2000 truth[(truth[,1]=="G3" & > truth[,2]=="G2") | (truth[,1]=="G2" & truth[,2]=="G3"),3]<-1 > ###############################3Q:# i want make loop take all 2000 rows and > comparsion between all values in row one and row two : > #Gi(value in row1), Gj(value in row2) > #Gj(varow1),Gi(row2), #############more :#here just G2 and G3, i want make > loop to cam[are all values from G1 to G2000 truth[(truth[,1]=="G3" & > truth[,2]=="G2") | (truth[,1]=="G2" & truth[,2]=="G3"),3]<-1 > (Simply they regulate the other. If element A is in the first group , and it > is related to element B in the second group , and element B also in in the > first group , and it is related to element A(the same element in the first > group) in the second group , we write 1 and otherwise 0. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.