Dear All,

I am a newbee in R an have the following problem. I have variables AB,BC,CD
to which outputs are assigned. Now AB[,1], for example, outputs a list,
which is a random combination of the following characters: "AB", "BC", "CD".
What I want to do is to build a 3x3 matrix with colnames and rownames equal
to "AB", "BC", "CD". Matrix values TRUE or FALSE shall then be automatically
assigned. Hence, if a colname of the matrix is represented in output AB, the
assigned value should be TRUE and otherwise FALSE.

I tried to do the following:

c.matrix<-matrix(NA,ncol=3,nrow=3);

colnames(c.matrix)<-cbind("AB", "BC", "CD");rownames(c.matrix)<-cbind("AB",
"BC", "CD");

c.matrix<-as.data.frame(c.matrix)


which produces:


        AB BC CD

AB  NA  NA  NA

BC  NA  NA  NA

CD  NA  NA  NA


Then for column AB I tried this in order to assign the TRUE/FALSE values to
the NA matrix:


for(i in 1:3)) {if (length(intersect(names(c.matrix)[[i]],AB[,1]))>0)
{c.matrix[[i,1]]=TRUE} else {condition.matrix[[i,1]]=FALSE}}


The output it produces is:


          AB  BC  CD

AB  <NA>  NA  NA

BC  <NA>  NA  NA

CD  FALSE  NA  NA


rather than something like:


          AB  BC  CD

AB  TRUE  NA  NA

BC  FALSE  NA  NA

CD  FALSE  NA  NA

What am I doing wrong? Thank you for your help.

Best Regards

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to