Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How can i estimate the median in R using the median fuction?

$
0
0

i am trying to calculate some statistical moments, using the moments function, for a group of variables. In order to do this i try to program a function

When I try to use my function with my dataframe that does not have NA or missing, I confirmed that the data is clean, I have the next error:

library(moments)

summary.stat0 = function(data){ 
  SUM = matrix(NA,ncol=ncol(data),nrow=7)
  colnames(SUM) = colnames(data) 
  rownames(SUM) = c("Mean","Median","Maximum","Minimum","Std. Dev.","Skewness","Kurtosis")
  for (i in 1:ncol(data)) {
    SUM[1,i] = mean(data[,i])
    SUM[2,i] = median(data[,i])
    SUM[3,i] = max(data[,i])
    SUM[4,i] = min(data[,i])
    SUM[5,i] = sd(data[,i])
    SUM[6,i] = skewness(data[,i])
    SUM[7,i] = kurtosis(data[,i])
  }
  SUM
}

Error in median.default(data[i]) : need numeric data In addition: Warning message: In mean.default(data[, i]) :

If someone can help me with this function i will be grateful


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>