[R] apply/looping query

Laura Quinn laura at env.leeds.ac.uk
Wed Jun 16 17:34:32 CEST 2004


I have several large matrices each having perhaps one or two
data points missing. For instance one point in 2881 is missing. As I want to perform
various analyses on these matrices I feel it is not
unreasonable to linearly interpolate over the missing points. I want to basically "fill in
the gaps" of the original matrix - the following piece of code
doesn't work and i'm not sure where i'm going wrong:

x=1:2881
my.new.matrix<-matrix(nrow=2881,ncol=20)
for(i in 1:20){
my.new.matrix[[i]]<-approx(x,my.matrix[,i],n=2881)
}

the error message says:

Error: more elements supplied than there are to replace

where am I going wrong??

Thanks in advance..
Laura




More information about the R-help mailing list