Hi all,

 

I'm have a matrix (X) with observations as rows and parameters as columns. I'm 
trying to exchange all missing values in a column by the column mean using the 
code below, but so far, nothing happens with the NAs... Can anyone see where 
the problem is?

 

N<-nrow(X) # Calculate number of rows = 108
p<-ncol(X) # Calculate number of columns = 88
   

# Replace by columnwise mean
for (i in colnames(X)) # Do for all columns in the matrix
{ 
   for (j in rownames(X)) # Go through all rows
   {
      if(is.na(X[j,i])) # Search for missing value in the given position
      {
         X[j,i]=mean(X[1:p, i]) # Change missing value to the mean of the column
      }
   }
} 

 

All the best,

 

Joel

 


 
                                          
_________________________________________________________________
Hitta hetaste singlarna på MSN Dejting!
http://dejting.se.msn.com/channel/index.aspx?trackingid=1002952
        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to