Board logo

标题: R基础课(7) [打印本页]

作者: look_w    时间: 2019-2-20 19:24     标题: R基础课(7)

4. R基本函数请查看:R参考卡片,

5. R的扩展包1). plyr (数据处理)
plyr是一个数据处理的包,可以把大的数据集通过一些条件拆分成小的数据集的功能包。
数据集baseball(http://www.baseball-databank.org/)
21,699 records covering 1,288 players, spanning 1871 to 2007
举例:击球得分:RBI(Run batted in)
install.packages("plyr")library(plyr)?baseballddply(baseball, .(lg), c("nrow", "ncol"))rbi <- ddply(baseball, .(year), summarise, mean_rbi = mean(rbi, na.rm = TRUE))plot(mean_rbi ~ year, type = "l", data = rbi)
2). stringr (字符串处理)
stringr是一个字符串处理的包,可以方便地进行各种字符串的操作。
install.packages("stringr")library(stringr)fruits <- c("one apple", "two pears", "three bananas")str_replace(fruits, "[aeiou]", "-")str_replace_all(fruits, "[aeiou]", "-")str_replace_all(fruits, "([aeiou])", "")str_replace_all(fruits, "([aeiou])", "\\1\\1")str_replace_all(fruits, "[aeiou]", c("1", "2", "3"))str_replace_all(fruits, c("a", "e", "i"), "-")3). ggplot2 (可视化)
ggplot2专业级的可视化绘图包
install.packages("ggplot2")library(ggplot2)g<-ggplot(mtcars, aes(x=factor(cyl), fill=factor(vs)))g+geom_bar(position="dodge")




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0