-3

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

  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with your code so far and the desired result. Tell us where exactly you are getting stuck. – MrFlick Oct 18 '20 at 03:43
  • `colMeans(iris[-5])` – Ronak Shah Oct 18 '20 at 03:53
  • i have colMeans(iris[,4]) but i cant my iris data - mean – Yanto basna Oct 18 '20 at 04:46

1 Answers1

0

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)