[R] missing values
jim holtman
jholtman at gmail.com
Fri Nov 23 21:37:11 CET 2007
you could use this instead of the last two statements; don't know if
it makes any simpler since it is just combining into one statement
what you had in two:
data$y[is.na(data$y)] <- means[is.na(data$y)]
On Nov 23, 2007 1:49 PM, lamack lamack <lamac_k at hotmail.com> wrote:
>
>
>
> Dear all, there is a best way to do the following task?
>
> x = rep(c("A","B"),5)
> y = rnorm(10)
> data = data.frame(x,y)
> data$y[1:2] = c(NA,NA)
> means = ave(data$y,as.character(data$x),FUN=function(x)mean(x,na.rm=T))
> aux = which(is.na(data$y))
> data[aux,"y"] = means[aux]
> _________________________________________________________________
> Encontre o que procura com mais eficiência! Instale já a Barra de Ferra[[replacing trailing spam]]
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list