"R 그룹별 합 구하기"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
==개요==
==개요==
;R 그룹별 합 구하기
;R 그룹별 합 구하기
* 대략 SQL의 "SELECT SUM(ea) GROUP BY fruit"


<source lang='r'>
<source lang='r'>

2019년 8월 25일 (일) 16:36 판

1 개요

R 그룹별 합 구하기
  • 대략 SQL의 "SELECT SUM(ea) GROUP BY fruit"
df <- read.csv( header=T, stringsAsFactors=FALSE, text="
day,fruit,ea
2019-06-01,apple,1
2019-06-11,apple,1
2019-06-21,banana,2
2019-07-01,apple,3
2019-07-11,banana,4
2019-08-25,orange,2
")

aggregate(ea ~ fruit, df, sum)
##    fruit ea
## 1  apple  5
## 2 banana  6
## 3 orange  2

tapply(df$ea, df$fruit, sum)
## apple banana orange 
##     5      6      2

2 같이 보기

3 참고

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