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

잔글 (봇: 자동으로 텍스트 교체 (-<source +<syntaxhighlight , -</source> +</syntaxhighlight>))
28번째 줄: 28번째 줄:


==같이 보기==
==같이 보기==
{{z컬럼3|
* [[R table()]]
* [[R table()]]
* [[R sqldf()]]
* [[R sqldf()]]
* [[R length()]]
* [[R length()]]
* [[R aggregate()]]
* [[R aggregate()]]
* [[R 행수 확인]]
* [[R 그룹별 합 구하기]]
* [[R 그룹별 합 구하기]]
* [[SQL 그룹별 건수 구하기]]
* [[SQL 그룹별 건수 구하기]]
}}


[[분류: R 데이터 전처리]]
[[분류: R 데이터 전처리]]
[[분류: R sqldf]]
[[분류: R sqldf]]

2021년 10월 3일 (일) 02:43 판

1 개요

R 그룹별 건수 구하기
  • 대략 "SELECT fruit, COUNT(ea) FROM df GROUP BY fruit"
df <- read.csv( header=T, stringsAsFactors=F, 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
")

# 방법 1
aggregate(ea ~ fruit, df, length)
# 방법 2
table(df$fruit)
# 방법 3
library(sqldf)
sqldf("SELECT fruit, COUNT(ea) AS cnt FROM df GROUP BY fruit")

2 같이 보기

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