I am trying to find the skewness for the variable galaxies in the MASS data library
I have outlined the formula for skewness, then loaded the MASS package, defined galaxies dataset, but get an error as n is undefined in the skewness formula. I am not sure if I need to include an n or not, as I just want my sample size to be all results in galaxies.
My code is
myskewness = function(x) {
n = length(x)
xbar = sum(x) / n
myskewness = (sqrt(n) * sum((x - xbar)^3)) / sum((x -xbar)^2)^(3 / 2)
return(myskewness)
}
gal <- galaxies
myskewness(gal)
Error in myskewness(gal) : object 'n' not found