|
发表于 2022-9-2 19:05:31
|
查看: 1114 |
回复: 0
数据透视表
R提供了apply系列函数,包括apply,lapply,sapply,tapply,vapply等,可以对二维数据进行计算,并且可以分组进行统计,类似于Excel中的数据透视表功能。
- rm(list = ls())
- x <- read.xlsx('2015.xlsx')
- head(x)
- is.factor(x$Province)
- table(x$Province)
- sort(table(x$Province))
- sort(table(x$Province),decreasing = T)
- barplot(sort(table(x$Province),decreasing = T),las = 2)
- barplot(sort(table(x$Province),decreasing = T),las = 2,col = 'orange',border = F)
- abline(h =2)
- abline(h =4)
- abline(h =6)
- abline(h =8)
- abline(h =c(10,12,14))
- tapply(x$Income,x$Province,mean)
- aggregate(x$Income,by=list(x$Province),mean)
- state.center
- lapply(state.center,sum)
- sapply(state.center,sum)
- table(state.division)
- table(state.region)
- tapply(state.x77$Income, state.division, mean)
- # Error in state.x77$Income : $ operator is invalid for atomic vectors
- class(state.x77)
- state.x77 <- as.data.frame(state.x77)
- tapply(state.x77$Income, state.division, mean)
- sort(tapply(state.x77$Income, state.division, mean))
- sort(tapply(state.x77[size=5][b]数据透视表 [/b][/size]
- R提供了apply系列函数,包括apply,lapply,sapply,tapply,vapply等,可以对二维数据进行计算,并且可以分组进行统计,类似于Excel中的数据透视表功能。
- Life Exp`, state.division, mean))
- sort(tapply(state.x77$Murder, state.division, mean))
复制代码
|
|