生信星球培训第四十五期

学习小组Day--6笔记--丁览博

2020-03-21  本文已影响0人  丁览博

学习R包

day6 思维导图

图片来自于ipad OS端mindnode

学习与加载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)

dplyr五个基本函数

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

  1. 新增列


    mutae
  1. 筛选列
  1. 筛选行


  1. 对表格排序
  1. 汇总

dplyr两个实用节能

  1. 管道操作(ctrl+shift+m ==》%>%)
> test %>% 
+ group_by(Species) %>% 
+ summarise(mean(Sepal.Length),sd(Petal.Width)) 

2.统计某列的unique值
count(test,colname)

dplyr处理关系数据

  1. 内连取交集
> inner_join(test1,test2,by='x')
  x z y
1 b A 2
2 e B 5
3 f C 6
  1. 左连
> left_join(test1,test2,by='x')
  x z  y
1 b A  2
2 e B  5
3 f C  6
4 x D NA
> left_join(test2,test1,by='x')
  x y    z
1 a 1 <NA>
2 b 2    A
3 c 3 <NA>
4 d 4 <NA>
5 e 5    B
6 f 6    C
  1. 全连
> full_join(test1,test2,by='x')
  x    z  y
1 b    A  2
2 e    B  5
3 f    C  6
4 x    D NA
5 a <NA>  1
6 c <NA>  3
7 d <NA>  4
  1. 半连接

  2. 反连接

  3. 简单合并

> bind_rows(test1,test2)
  x  y
1 1 10
2 2 20
3 3 30
4 4 40
5 5 50
6 6 60
> bind_cols(test1,test3)
  x  y   z
1 1 10 100
2 2 20 200
3 3 30 300
4 4 40 400
上一篇下一篇

猜你喜欢

热点阅读