生信人

找回密码
立即注册
搜索
热搜: 活动 交友 discuz
发新帖

0

收听

12

听众

279

主题
发表于 2022-9-2 19:05:31 | 查看: 606| 回复: 0
数据透视表
       R提供了apply系列函数,包括apply,lapply,sapply,tapply,vapply等,可以对二维数据进行计算,并且可以分组进行统计,类似于Excel中的数据透视表功能。
  1. rm(list = ls())
  2. x <- read.xlsx('2015.xlsx')
  3. head(x)
  4. is.factor(x$Province)
  5. table(x$Province)
  6. sort(table(x$Province))
  7. sort(table(x$Province),decreasing = T)
  8. barplot(sort(table(x$Province),decreasing = T),las = 2)
  9. barplot(sort(table(x$Province),decreasing = T),las = 2,col = 'orange',border = F)
  10. abline(h =2)
  11. abline(h =4)
  12. abline(h =6)
  13. abline(h =8)
  14. abline(h =c(10,12,14))
  15. tapply(x$Income,x$Province,mean)
  16. aggregate(x$Income,by=list(x$Province),mean)

  17. state.center
  18. lapply(state.center,sum)
  19. sapply(state.center,sum)
  20. table(state.division)
  21. table(state.region)

  22. tapply(state.x77$Income, state.division, mean)
  23. # Error in state.x77$Income : $ operator is invalid for atomic vectors
  24. class(state.x77)
  25. state.x77 <- as.data.frame(state.x77)
  26. tapply(state.x77$Income, state.division, mean)
  27. sort(tapply(state.x77$Income, state.division, mean))
  28. sort(tapply(state.x77[size=5][b]数据透视表 [/b][/size]
  29.        R提供了apply系列函数,包括apply,lapply,sapply,tapply,vapply等,可以对二维数据进行计算,并且可以分组进行统计,类似于Excel中的数据透视表功能。
  30. Life Exp`, state.division, mean))
  31. sort(tapply(state.x77$Murder, state.division, mean))
复制代码

您需要登录后才可以回帖 登录 | 立即注册

QQ|Archiver|手机版|小黑屋|生信人

GMT+8, 2024-5-4 18:51 , Processed in 0.040115 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表