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.

Anyways, suppose i have the following data.


    data <- as.data.frame(matrix(rnorm(100), nrow = 10))

And let's put some missing values

    data[sample(1:10, 3), sample(1:10, 3)] <- NA

I want to replace all NA's by row averages or column averages of my matrix.

I tried to use(with my original data matrix)

    data[is.na(data)] <- rowMeans(data, na.rm = TRUE)
But got an error message of

       Error in rowMeans(data, na.rm = TRUE) : 'x' must be numeric
Then I converted  data<- as.matrix(data)
                  data<- as.numeric(data)
And applying my code

     data[is.na(data)] <- rowMeans(data, na.rm = TRUE)

Error message


      Error in rowMeans(data, na.rm = TRUE) : 
  'x' must be an array of at least two dimensions

Then again i tried to convert it into Arrays....but the errors continues....

I Also tried the code

    data[is.na(data)] <- apply(data,1,mean)

But still didnt work out.

Can anyone pls help me as to how to fix it and get out of this, please?

Thank you very much

Daniel


      
	[[alternative HTML version deleted]]

