1) We don't have your previous email and I doubt anyone here committed your
code to memory
2) No offense but this post is still an eye sore. Actually I am guessing
even worse than the first because there is no working example. The idea is
to provide *minimal* code that reproduces the problem - without extra
info/functionality (setting attributes, stages of the simulation not needed
etc.).
3) There is (still ?)  important info missing like what does "fail" mean ?
with what error ? at what stage of the simulation (initialization ? last
stage ? different iteration every time ? ).
4) Your pseudo-code is worthless as any number of things can go wrong, for
e.g. (but not limited to):
consider your statement
> which.duplicate <- sample(ncol(matrix[[I]], number.to.delete, replace=F)
a) number.to.delete/duplicate is not an integer
b)  missing a closing on ncol(),
c)  supposed to be  number.to.duplicate
d) ncol(matrix[[I]]) is less than number.to.delete/duplicate
...
5) In the mean time, you could try adding print statements to different
objects in your function so if it is the random component in the simulation
causing the fail, you'll see the origin (e.g. prop.to.delete == 1).

HTH

On Tue, Feb 5, 2013 at 4:42 AM, Benjamin Ward (ENV) <b.w...@uea.ac.uk>wrote:

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

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