[R] handling missing values

R. Michael Weylandt michael.weylandt at gmail.com
Thu Mar 15 19:45:06 CET 2012


Try adding na.action = na.exclude to your call to gam.

Michael

On Thu, Mar 15, 2012 at 1:00 PM, Mintewab Bezabih
<Mintewab.Bezabih at economics.gu.se> wrote:
> Dear R users,
>
> I have problems handling missing values. THe problem is that after running my codes the result I get just skips the missing values. What I want is for the missing values to appear in my results as well. I have put a workable example below and as you could see the missing value in x1 (the 18thh value) does not appear in the list y.fitted.
>
> Any help appreciated
>
> Regards,
> minti
>
> library(mgcv)
> y.list <- list(y1=runif(10), y2 <- runif(10), y3 <- runif(10))
> y.list <- list(y1=runif(20))
> x1 <- 1:20
> x2 <- c(11, 15, 17, 2, 18, 6, 7, NA, 12, 10,21, 25, 27, 12, 28, 16, 17, NA, 12, 10)
> y.gam <-lapply(y.list, function(y)gam(y~s(x1,x2, k=10)))
> y.fitted <- lapply(y.gam, fitted) # list of fitted values
>
> ______________________________________________
> 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.



More information about the R-help mailing list