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
Laura Quinn wrote:> 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??approx() returns a list with $x and $y components I'd use [,x] instead of [[i]] to replace columns. Hence: for(i in 1:20){ my.new.matrix[,i]<-approx(x,my.matrix[,i],n=2881)$y } Baz