[R] help, please! matrix operations inside 3 nested loops

Fridolin smells_like_rock at gmx.net
Thu Aug 9 12:53:40 CEST 2012


all problems solved. thank you for your help!
for the sake of completeness, here my solution:
#1) read in data:
daten<-read.table('K:/Analysen/STRUCTURE/test.txt', header=TRUE, sep="\t")
daten<-as.data.frame(daten)

#2) create empty matrix:
indxind<-matrix(0,nrow=617, ncol=617) 
#indxind[1:20,1:19]

#3) compare cells to each other, score:
#for the whole dataset: s in 3:34, z1 in 1:617, z2 in 1:617
z1<-1 #running variable for rows in daten
z2<-1 #running variable for rows in daten
l1<-1 #running variable for rows in indxind
l2<-1 #running variable for rows in indxind
for (s in 3:6) {   #walks though the matrix colum by colum, starting at
colum 3
                while (z1<11) {  #for each current colum, take one row
(z1)...
                                while (z2<11) {  #...and compare it to
another row (z2) of the current colum
                                              if (z1!=z2) {
                                                          l1
                                                         
topf<-indxind[l1,l2]
                                                          if
(daten[z1,s]==daten[z2,s]) topf<-topf+1   #actually, 2 rows make up 1
individual,
                                                          if
(daten[z1,s]==daten[z2+1,s]) topf<-topf+1      #therefore i compare 2 rows
                                                          if
(daten[z1+1,s]==daten[z2,s]) topf<-topf+1      #with another 2 rows
                                                          if
(daten[z1+1,s]==daten[z2+1,s]) topf<-topf+1
                                                         
indxind[l1,l2]<-topf
                                                          }
                                              z2<-z2+2
                                              l2<-l2+1
                                              }
                                z2<-1
                                l2<-1
                                z1<-z1+2
                                l1<-l1+1
                              }
                z1<-1
                l1<-1
               }

#4) check:
indxind[1:5,1:5]



--
View this message in context: http://r.789695.n4.nabble.com/help-please-matrix-operations-inside-3-nested-loops-tp4639592p4639744.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list