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
            Asked
            
        
        
            Active
            
        
            Viewed 597 times
        
    -3
            
            
        - 
                    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 Answers
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)
 
    
    
        Surbhi Anand
        
- 1
- 4
- 
                    
- 
                    
- 
                    i mean each data of column - mean of that column so the answer is matrix 150x4 – Yanto basna Oct 18 '20 at 04:45
- 
                    yeah, so then remove /sd(numbers) in normalize function and it will serve your purpose. – Surbhi Anand Oct 18 '20 at 04:52
