permutation loop
1
0
Entering edit mode
Kripa R ▴ 180
@kripa-r-4482
Last seen 10.2 years ago
Hello, I'm at an impasse in my coding and any help would be greatly appreciated. Below is my current code: nr=dim(fileName)[1] #number of rows count=0 for(i in 1:nr) { for (j in 1:nr) { if(fileName$Individual[i]==fileName$Individual[j] & i != j) #look for a pair in the column { count=count+1 perm<-sample(fileName$Group) #permutate sample group if(count==1)break; } } } In the matrix (fileName), first it searches for a pair in column: Individual, and once identified it permutes another column (Group). I would like this process to repeat itself to produce all unique outputs for the perm variable. If each unique permutation had its own name or was in a matrix that would be very helpful. ie perm1: TCTTCT perm2: CTTTCT perm3: TCTTTC... Hopefully that makes sense, thanks in advance group! [[alternative HTML version deleted]]
PROcess PROcess • 1.1k views
ADD COMMENT
0
Entering edit mode
@achilleas-pitsillides-4316
Last seen 10.2 years ago
Hey, I don't think this is the most efficient way to do this but here it goes: #Create a random names vector with some repeated names names.col <- sample(paste("name",1:4,sep =""),10,replace=T) print(names.col) #Now find all pairs that are the same temp <- sapply(names.col,rep,length(names.col)) boolean.matrix <- temp==t(temp) #The entries for which the names are the same ar e True # The above counts the pairs twice and includes the diagonal elements so to remove those result <- boolean.matrix & upper.tri(boolean.matrix) result.matrix <- which(result,arr.ind=T) #The result.matrix contains one row for each pair a nd two columns holding the indices of the matching pairs. So you can then loop over the result.matrix rows and do whatever you need for each of the matching pairs. cheers, Achilleas On Thu, Nov 17, 2011 at 3:40 PM, Kripa R <kripa777@hotmail.com> wrote: > > Hello, > I'm at an impasse in my coding and any help would be greatly appreciated. > Below is my current code: > > nr=dim(fileName)[1] #number of rows > count=0 > > for(i in 1:nr) { > for (j in 1:nr) { > if(fileName$Individual[i]==fileName$Individual[j] & i != j) #look for a > pair in the column > { > count=count+1 > perm<-sample(fileName$Group) #permutate sample group > if(count==1)break; > } > > } > } > > > In the matrix (fileName), first it searches for a pair in column: > Individual, and once identified it permutes another column (Group). > > I would like this process to repeat itself to produce all unique outputs > for the perm variable. If each unique permutation had its own name or was > in a matrix that would be very helpful. ie perm1: TCTTCT perm2: CTTTCT > perm3: TCTTTC... > > > Hopefully that makes sense, thanks in advance group! > > [[alternative HTML version deleted]] > > _______________________________________________ > Bioconductor mailing list > Bioconductor@r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD COMMENT

Login before adding your answer.

Traffic: 784 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6