data analysis & visualization

ddply와 setDT 비교

R2019. 11. 11. 01:59

속도로 보았을 때 ddply 보다 setDT의 속도가 월등히 빠르다. 이에 따라 예제 코드를 아래와 같이 제시한다. 

 

library(plyr)
data(iris)
temp=ddply(iris,.(Species),summarise,mean=mean(Sepal.Length))
temp=data.table::setDT(iris)[,.(mean=mean(Sepal.Length)),'Species']library(plyr)
data(iris)
temp=ddply(iris,.(Species),summarise,mean=mean(
Sepal.Length))
temp=data.table::setDT(iris)[,.(mean=mean(Sepal.Length)),'Species']

temp2=reshape2::melt(temp,id='Species')
library(ggplot2)
ggplot(temp2, aes(Species, value, fill=factor(Species)))+
  geom_bar(stat='identity', position = 'dodge')+coord_flip()