安裝加載R包
options(BioC_mirror="http://mirrors.tuna.tsinghua.edu.cn/bioconductor/")
options("repos" = c(CRAN="http://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
用options函數(shù)設(shè)置R運(yùn)行過程中的鏡像
安裝dplyr
install.packages("dplyr")
加載dplyr
library(dplyr)
查看dplyr中的指令
ls("package:dplyr")
使用示例數(shù)據(jù)學(xué)習(xí)dplyr基礎(chǔ)函數(shù)

1.png
1.mutate(),用于新增列
test<-(mutate(test,new=Sepal.Length*Sepal.Width)) #新增列名為new。2.select(),用于按列篩選
select(test,one_of("Sepal.Length","Petal.Length"))
2.png
3.filter()用于篩選行

3.png
4.arrange(),排序。默認(rèn)從小到大,desc從大到小。

4.png
5.summarise() 用于匯總。
mean():計(jì)算平均值
sd():計(jì)算方差
group_by( ):分組

5.png
dplyr兩個(gè)實(shí)用技能
1.管道操作 符號 %>% ,快捷鍵Ctrl+Shift+M
%>%:將左側(cè)準(zhǔn)備的數(shù)據(jù)或表達(dá)式,傳遞給右側(cè)的函數(shù)調(diào)用或表達(dá)式進(jìn)行運(yùn)行

6.png
2.coount()統(tǒng)計(jì)某列的unique值

7.png
dplyr處理關(guān)系數(shù)據(jù)
1.內(nèi)連inner_join,取交集,通過相同的元素連接
2.左連left_join,左邊的表格連在左邊
3.全連full_join
4.半連接semi_join,顯示連接表2能與表1匹配的部分
5.反連接anti_join,顯示無法匹配的部分
6.簡單合并 bind_rows(),合并行,需要兩個(gè)表格相同列數(shù)
bind_cols(),合并列,需要兩個(gè)表格相同行數(shù)。