Re: [R] replacing missing values with row average

2011-02-27 Thread Bert Gunter
Warning: This is not a helpful answer. Actually, it's a question: Why do you want to do this? Replacing missing values with row or column averages and then analyzing the data as if the missing values were not there is a dangerous thing to do it can produce biased estimates and understate the true e

Re: [R] replacing missing values with row average

2011-02-27 Thread Joshua Wiley
Hi Daniel, If your data is stored in a matrix, the following should work (and be fairly efficient): # dat <- matrix(rnorm(100), nrow = 10) dat[sample(1:10, 3), sample(1:10, 3)] <- NA ## create an index of missing values index <- which(is.na(dat), arr.ind = TRUE) ## calculate the row m

[R] replacing missing values with row average

2011-02-27 Thread Daniel M.
Hello, I have some dataset, which i read it from external file using the (data <- read.csv("my file location")) and read as a dataframe > is(data) [1] "data.frame" "list" "oldClass" "vector" but i have also converted this into a matrix and tried to apply my code but didnt work. Anywa