學(xué)習(xí)小組day6筆記-R包-Sara

安裝和加載R包

dplyr五個基礎(chǔ)函數(shù)

dplyr兩個實(shí)用技能

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

安裝和加載R包

install.packages(“包”)
BiocManager::install(“包”)  #安裝包
library(包)
require(包)   #加載包

eg.

Error:

  1. Warning message:
    程輯包‘dplyr’是用R版本4.1.3 來建造的
    Solution:
    先打開R的GUI,在進(jìn)行如下操作。
install.packages("installr")
library(installr)
updateR()
  1. The following objects are masked from ‘package:stats’:decompose, spectrum
    解決方法:
library(igraph,warn.conflicts = F) 
 # 去除警告

https://blog.csdn.net/ouyangk1026/article/details/122165567

dplyr五個基礎(chǔ)函數(shù)

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列或某幾列對整個表格進(jìn)行排序

arrange(test, Sepal.Length)#默認(rèn)從小到大排序
arrange(test, desc(Sepal.Length))#用desc從大到小

summarise():匯總

summarise(test, mean(Sepal.Length), sd(Sepal.Length))# 計(jì)算Sepal.Length的平均值和標(biāo)準(zhǔn)差

dplyr兩個實(shí)用技能

管道操作

%>% (cmd/ctr + shift + M)

test %>% 
  group_by(Species) %>% 
  summarise(mean(Sepal.Length), sd(Sepal.Length))
最后編輯于
?著作權(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)容