Hi all,

I realised that my last email question and code was probably going to be a bit 
of an eyesore for some people and that perhaps the best thing for me to do is 
to pose the question of what it is I want to achieve, rather than what I've 
written, if it helps people:

I'm writing a simulation, and during that simulation I have a list of matrices 
– of variable number of columns.
For every matrix in this list I want to randomly select a proportion of them 
for removal from the matrix, and a proportion for duplication. Proportions of 
columns to be duplicated of deleted are set out in a n by 2 matrix:

Delete      Duplicate
0.99 0.43
0.34                0.32
0.54                0.56
….. And so on.

So for each matrix in the list of matrices, I want to:


  *   Calculate the number of columns to be deleted or duplicated: something 
like
     *   number.to.delete <- ncol(matrix list[[I]])*proportionsmatrix[I,1]
     *   number.to.duplicate <- ncol(matrix list[[I]])*proportionsmatrix[I,2]
  *   Then I want to sample the columns to be deleted, and those to be copied : 
something like:
     *   which.delete <- sample(ncol(matrix[[I]], number.to.delete, replace=F)
     *   which.duplicate <- sample(ncol(matrix[[I]], number.to.delete, 
replace=F)
  *   Then I want to make the new matrices: something like:
     *   new.matrices<- matrix[,-which.delete]
     *   new.matrices<-cbind(new.matrices, matrix[,which.duplicate]

>From my previous email you'll see I did this by making a function which will 
>do this for one matrix out of the entire list, and the applying the function 
>to the entire list with lapply. Which works when I copy and paste the code 
>into R with usable data, but as part of the simulation it fails. This is 
>strange since I do other similar operations on these matrices without problem, 
>with the same method of indexing. Debug() and running the sim step by step the 
>data does not appear to be altered such that would affect the function.

Best,
Ben.





        [[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