R 그룹별 건수 구하기

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 }}