R colSums()

1 개요[ | ]

R colSums()
  • Form Column Sums
matrix
m <- matrix(1:6, nrow=3, ncol=2)
m
##      [,1] [,2]
## [1,]    1    4
## [2,]    2    5
## [3,]    3    6
colSums(m)
## [1]  6 15
data.frame
mydf <- read.table( header=TRUE, stringsAsFactors=FALSE, text="
English Math
     30   60
     40   70
     50   80
     60   90
")
mydf
##   English Math
## 1      30   60
## 2      40   70
## 3      50   80
## 4      60   90

colSums(mydf)
## English    Math 
##     180     300

sapply(mydf, sum)
## English    Math 
##     180     300 

apply(mydf, 2, sum)
## English    Math 
##     180     300

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}