Calculate Data Iris with Mean of Column

702 views Asked by At

I have problem in R with Data Iris, Let us know how to calculate iris data - mean of all column (4 column) in iris data with looping

1

There are 1 answers

4
Surbhi Anand On

This should work.

data("iris")
    iris.numeric <- iris[,c(1:4)]
    colMeans(iris.numeric)
    
    for (i in 1:4) { 
      print(mean(iris[,i]))
      }
    
    normalize <- function(numbers)
                 {    (numbers - mean(numbers))/sd(numbers)
                 }
    new.iris <- apply(iris.numeric, 2, normalize)
    apply(new.iris, 2, mean)
    apply(new.iris, 2, sd)