使用内置的mtcars
统计频数
table(mtcars$gear)
统计频率
paste0(round(prop.table(table(mtcars$gear)),2)*100,’%’)
统计频率的另一种方法,使用arregate
total<-length(mtcars
gear)b<−aggregate(mtcars
gear,by=list(mtcars
gear),length)b
x/total
cbind(b,b$x/total)