[R] help with a simple function

wacguy gw57 at duke.edu
Fri Sep 13 06:14:41 CEST 2013


hi, I am new to are, very new and want to ask what's wrong with this
function: It is suppose to read a table and return its matrix transposed
with NA replaced by the average of each column and a row of means at the
bottom row. The separated parts are returned correctly. Thanks a lot for any
help.

Guy

write.table=function(durty_data){
  
  
  dt.table=read.table(durty_data, sep = "\t", header=T)#
  y_raw_mt=as.matrix(dt.table[2:174])####
  rownames(y_raw_mt)=y_raw[,1] #assigning the raw names to the matrix
  y_raw_mt_t=t(y_raw_mt)####
  y_raw_mt_t_mean=apply(y_raw_mt_t, 2, mean, na.rm=T)###
  means=c(y_raw_mt_t_mean)##
  
  y_raw_mt_t_meanbind=rbind(y_raw_mt_t,means)##
  
 
  t=function(x) { 
    x[is.na(x)]  = mean(x, na.rm = T) 
    return(x) 
  }
  
  write.a.nice.table=apply(y_raw_mt_t_meanbind,2,t)
  return(write.a.nice.table)
}



--
View this message in context: http://r.789695.n4.nabble.com/help-with-a-simple-function-tp4676026.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list