calculate mean for multiple columns in data.frame

后端 未结 3 1096
温柔的废话
温柔的废话 2020-12-16 23:27

Just wondering whether it is possible to calculate means for multiple columns by just using the mean function

e.g.

mean(iris[,1])

i

3条回答
  •  爱一瞬间的悲伤
    2020-12-17 00:03

    Your above solution does work assuming the columns are in the correct is.numeric format. See below example:

    a <- c(1,2,3)
    mean(a)
    
    b <- c(2,4,6)
    mean(b)
    
    d <- c(3,6,9)
    
    mydata <- cbind(b,a,d)
    
    
    mean(mydata[,1:3])
    

提交回复
热议问题