学习小组day6笔记-R包-Sara
2022-05-13 本文已影响0人
sarashang
安装和加载R包
dplyr五个基础函数
dplyr两个实用技能
dplyr处理关系数据
安装和加载R包
install.packages(“包”)
BiocManager::install(“包”) #安装包
library(包)
require(包) #加载包
eg.
Error:
- Warning message:
程辑包‘dplyr’是用R版本4.1.3 来建造的
Solution:
先打开R的GUI,在进行如下操作。
install.packages("installr")
library(installr)
updateR()
- The following objects are masked from ‘package:stats’:decompose, spectrum
解决方法:
library(igraph,warn.conflicts = F)
# 去除警告
https://blog.csdn.net/ouyangk1026/article/details/122165567
dplyr五个基础函数
mutate(),新增列
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),]
mutate(test, new = Sepal.Length * Sepal.Width)
select(),按列筛选
select(test,1)
select(test,c(1,5))
select(test,Sepal.Length)
filter()筛选行
filter(test, Species == "setosa")
filter(test, Species == "setosa"&Sepal.Length > 5 )
filter(test, Species %in% c("setosa","versicolor"))
arrange(),按某1列或某几列对整个表格进行排序
arrange(test, Sepal.Length)#默认从小到大排序
arrange(test, desc(Sepal.Length))#用desc从大到小
summarise():汇总
summarise(test, mean(Sepal.Length), sd(Sepal.Length))# 计算Sepal.Length的平均值和标准差
dplyr两个实用技能
管道操作
%>% (cmd/ctr + shift + M)
test %>%
group_by(Species) %>%
summarise(mean(Sepal.Length), sd(Sepal.Length))