一、安裝和加載R包
- 鏡像設(shè)置
https://mp.weixin.qq.com/s/XvKb5FjAGM6gYsxTw3tcWw
image.png - 安裝R包
R包安裝命令是
install.packages(“包”)或BiocManager::install(“包”)。取決于你要安裝的包存在于CRAN網(wǎng)站還是Biocductor,存在于哪里?可以谷歌搜到 - 加載包
library(包)或require(包) - 總結(jié)
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 函數(shù)
test <- iris[c(1:2,51:52,101:102),] # 設(shè)定一個test
(1) mutate(),新增列
image.png
(2) select(),按列篩選
(1)按列號篩選
image.png
image.png
(2)按列名篩選
select(test, Petal.Length, Petal.Width)
vars <- c("Petal.Length", "Petal.Width")
select(test, one_of(vars))
(3)filter()篩選行
filter(test, Species == "setosa")
(4)arrange(),按某1列或某幾列對整個表格進行排序
arrange(test, Sepal.Length)#默認從小到大排序
arrange(test, desc(Sepal.Length))#用desc從大到小



