生信星球培训第六十八期

《学习小组Day6笔记--万万》

2020-07-05  本文已影响0人  lzzzbone

学习R包

镜像设置

安装R包(以dplyr为例)

加载R包

options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")) 
options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/") 
install.packages("dplyr")
library(dplyr)

test <- iris[c(1:2,51:52,101:102),]

options("repos" = c(CRAN="http://mirrors.tuna.tsinghua.edu.cn/CRAN/")) 
options(BioC_mirror="http://mirrors.ustc.edu.cn/bioc/")

dplyr的五个基础函数

  1. mutate()#新增列

mutate(test, new = Sepal.Length * Sepal.Width)
注意严格区分大小写,新增列表指定示两列相乘

2.select()

select(test,1)
select(test,c(1,5))
select(test,Sepal.Length)
filter(test, Species == "setosa")#
filter(test, Species == "setosa"&Sepal.Length > 5 )
filter(test, Species %in% c("setosa","versicolor"))

4.arrange(),按某1列或某几列对整个表格进行排序,(默认从小到大排序)
5.summarise():汇总

dplyr实用技能

  1. 管道操作 %>% (cmd/ctr + shift + M)
    2.count统计某列的unique值

dplyr处理关系数据

即将2个表进行连接,注意:不要引入factor
1.內连inner_join,取交集
2.左连left_join
3.全连full_join
4.半连接:返回能够与y表匹配的x表所有记录semi_join
5.反连接:返回无法与y表匹配的x表的所记录anti_join
6.简单合并

上一篇 下一篇

猜你喜欢

热点阅读