Don't know about efficiency but here is one way:

# test data
A  <- matrix(1:54, ncol=6)
A[3,3] <- A[6,6] <- A[5,6] <- NA

f <- function(x) ifelse(is.na(x), mean(x, na.rm = TRUE), x)
apply(A, 2, f)

On 1/30/06, Julie Bernauer <[EMAIL PROTECTED]> wrote:
> Hello
>
> I am sorry fuch such a stupid question. Suppose I have a table of data having 
> a
> lot of NAs and I want to replace those NAs by the mean of the column before NA
> replacement. How is it possible to do that efficiently ?
>
> Thanks in advance,
>
> Julie
>
> --
> Julie Bernauer
> Yeast Structural Genomics
> http://www.genomics.eu.org
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to