學(xué)習(xí)小組Day6-學(xué)習(xí)R包————阿司匹林

1.dplyr五個基礎(chǔ)函數(shù)(數(shù)據(jù)使用內(nèi)置數(shù)據(jù)集iris)

1.mutate(),新增列

mutate(test, new = Sepal.Length * Sepal.Width)
image.png

2.select(),按列篩選

select(test,1)
select(test,c(1,5))
select(test,Sepal.Length)
image.png

(2)按列名篩選

select(test, Petal.Length, Petal.Width)
vars <- c("Petal.Length", "Petal.Width")
select(test, one_of(vars))
image.png

image.png

3.filter()篩選行
filter(test, Species == "setosa")


image.png

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

filter(test, Species %in% c("setosa","versicolor"))


image.png

4.arrange(),按某1列或某幾列對整個表格進(jìn)行排序
arrange(test, Sepal.Length)#默認(rèn)從小到大排序
image.png

arrange(test, desc(Sepal.Length))#用desc從大到小
image.png

5.summarise():匯總
summarise(test, mean(Sepal.Length), sd(Sepal.Length))# 計算Sepal.Length的平均值和標(biāo)準(zhǔn)差
image.png

group_by(test, Species)


image.png

summarise(group_by(test, Species),mean(Sepal.Length), sd(Sepal.Length))
image.png

2.dplyr兩個實用技能

1.管道操作 %>% (cmd/ctr + shift + M)


image.png

2:count統(tǒng)計某列的unique值


image.png

3.dplyr處理關(guān)系數(shù)據(jù)

1.內(nèi)連inner_join,取交集


image.png

image.png

inner_join(test1, test2, by = "x")


image.png

2.左連left_join
left_join(test1, test2, by = 'x')
image.png

left_join(test1, test2, by = 'x')


image.png

3.全連full_join
image.png

4.半連接:返回能夠與y表匹配的x表所有記錄semi_join
semi_join(x = test1, y = test2, by = 'x')
image.png

5.反連接:返回?zé)o法與y表匹配的x表的所記錄anti_join
anti_join(x = test2, y = test1, by = 'x')
image.png

6.簡單合并
test1 <- data.frame(x = c(1,2,3,4), y = c(10,20,30,40))
test1
test2 <- data.frame(x = c(5,6), y = c(50,60))
test2
test3 <- data.frame(z = c(100,200,300,400))
test3
bind_rows(test1, test2)
bind_cols(test1, test3)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容