学习小组Day6笔记-sukie
2020-06-11 本文已影响0人
李小琪_34e3
学习R包
1、镜像设置
编辑R的配置文件.Rprofile,Rstudio启动时会运行这个文件,相当于开机启动镜像配置。配置操作如下:
file.edit('~/.Rprofile')
在弹出的Rprofile框中添加options代码:
来自生信星球
# options函数就是设置R运行过程中的一些选项设置
options("repos" = c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")) #对应清华源
options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/") #对应中科大源
# 当然可以换成其他地区的镜像
保存,重启Rstudio,运行options()$repos
和options()$BioC_mirror
查看配置。

2、安装
R包安装命令install.packages("包")
或者BiocManager::install("包")
。取决于要安装的包存在于CRAN网站还是Bioconductor。
3、加载
加载命令包括:
library(包)
require(包)
安装加载三部曲(来自生信星球)
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),]
上述安装包dplyr五个基础函数使用:
1)mutate()
,新增列

2)
select()
,按列筛选按列号筛选:

按列名筛选:

注:
vars() :A character vector of variable names. When called from inside selecting functions like.
3)
filter()
,筛选行
4)
arrange()
,按某一列或某几列对整个表格进行排序
5)
summarise()
,汇总对数据进行汇总操作,结合group_by使用实用性强。

dplyr使用技能
1、管道操作%>%(cmd/ctr+shift+M)

2、count统计某列的unique值

dplyr处理关系数据
将2个表进行连接,注意不要引入factor??



