生信星球培训第四十八期

学习小组Day 6-小白要进步

2020-04-02  本文已影响0人  小白要进步

安装和加载R包

镜像设置

为了加快包的下载速度,需要设置镜像。

#编辑文件
file.edit('~/.Rprofile')
#添加镜像
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")) #对应清华源
options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/") #对应中科大源

安装和加载

#存在于CRAN的包
install.packages(" ")
library( )
#存在于Biocductor中的包
if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager")

BiocManager::install("ropls")

其他方法

dplyr五个基础函数

mutate(),新增列

test <- iris[c(1:2,51:52,101:102),]
mutate(test, new = Sepal.Length * Sepal.Width)
image.png
image.png

select(),按列筛选

按列号筛选

select(test,1)
image.png

按列名筛选

select(test, Petal.Length, Petal.Width)
image.png

filter()筛选行

filter(test, Species == "setosa")
image.png
filter(test, Species == "setosa"&Sepal.Length > 5 )
image.png

arrange(),按某1列或某几列对整个表格进行排序

arrange(test, Sepal.Length)#默认从小到大排序
arrange(test, desc(Sepal.Length))#用desc从大到小
image.png

summarise():汇总

# 先按照Species分组,计算每组Sepal.Length的平均值和标准差
group_by(test, Species)
summarise(group_by(test, Species),mean(Sepal.Length), sd(Sepal.Length))```
![image.png](https://img.haomeiwen.com/i19713265/42102fce2f94f753.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
上一篇 下一篇

猜你喜欢

热点阅读