Hello, I have a matrix in which two variables, x and y, are used together to determine z. The variables x and y are sorted into classes. Specifically, values for variable x range from 0 to 2.7 and are sorted into class increments of 0.15 and variable y ranges from 0-2100 with class increments of 100. For each x-y class combination, I have calculated a mean value of z from existing data. However there are gaps in the existing data (i.e., x-y combinations for which there are no z data). I would like to interpolate values to fill in these missing datapoints, but have so far been unable to find a straightforward way of doing so in R. There are many gaps in the data and I need to repeat this process for several individual datasets. That said, I am looking for a way to avoid interpolating each missing point separately. Any suggestions would be greatly appreciated. Regards, Jessica Schedlbauer
On May 2, 2010, at 5:27 PM, Jessica Schedlbauer wrote:> Hello, > > I have a matrix in which two variables, x and y, are used together > to determine z. The variables x and y are sorted into classes. > Specifically, values for variable x range from 0 to 2.7 and are > sorted into class increments of 0.15 and variable y ranges from > 0-2100 with class increments of 100. For each x-y class > combination, I have calculated a mean value of z from existing > data. However there are gaps in the existing data (i.e., x-y > combinations for which there are no z data). I would like to > interpolate values to fill in these missing datapoints, but have so > far been unable to find a straightforward way of doing so in R. > There are many gaps in the data and I need to repeat this process > for several individual datasets. That said, I am looking for a way > to avoid interpolating each missing point separately.Why not do a loess fit _before_ you do any binning and then predict.loess at the intervals where you want estimates? x=rnorm(200, 1.5) y= (10*x)^2 +rnorm(200, 0, 100) plot(x,y, cex=0.5, xlim=c(-2, 5)) points(seq(-2,5, by=0.15), predict(loess(y~x), newdata=data.frame(x=seq(-2,5, by=0.15))), col="red", cex=2)> > Any suggestions would be greatly appreciated. > > Regards, > Jessica Schedlbauer > > ______________________________________________ > R-help at 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.David Winsemius, MD West Hartford, CT
Are you looking for something like this? data <- data.frame(first= c(1,2,3,4,5,6,7,8), zehn = c(15,NA,NA,NA,NA,18,NA,25), ???? second = c(4,NA,7,9,NA,10.2,NA,12), ??? third= c(6,7,NA,NA,10,12,NA,16)) ? data ??? library(zoo) ??? data2 <-na.approx(data,na.rm=F) ??? data2 ?na.approx ? Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish & Wildlife Service California, USA ----- Original Message ----> From: Jessica Schedlbauer <jschedlb at fiu.edu> > To: "r-help at r-project.org" <r-help at r-project.org> > Sent: Sun, May 2, 2010 2:27:10 PM > Subject: [R] Question re: interpolation > > Hello,I have a matrix in which two variables, x and y, are used together> to determine z.? The variables x and y are sorted into classes.? > Specifically, values for variable x range from 0 to 2.7 and are sorted into > class increments of 0.15 and variable y ranges from 0-2100 with class increments > of 100.? For each x-y class combination, I have calculated a mean value of > z from existing data.? However there are gaps in the existing data (i.e., > x-y combinations for which there are no z data).? I would like to > interpolate values to fill in these missing datapoints, but have so far been > unable to find a straightforward way of doing so in R.? There are many gaps > in the data and I need to repeat this process for several individual > datasets.? That said, I am looking for a way to avoid interpolating each > missing point separately.Any suggestions would be greatly> appreciated.Regards, Jessica> Schedlbauer______________________________________________> ymailto="mailto:R-help at r-project.org" > href="mailto:R-help at r-project.org">R-help at r-project.org mailing list > href="https://stat.ethz.ch/mailman/listinfo/r-help" target=_blank > >https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting> guide http://www.R-project.org/posting-guide.htmland provide commented,> minimal, self-contained, reproducible code.