學(xué)習(xí)R包
感覺還是越來越難了拱镐,難度慢慢有點跳躍但是還是可以理解。仔細接觸之后還是覺得寫代碼還是比較有趣的玉转,邏輯思維很重要突想,雖然還是有點難度,難在于對于一些代碼不熟悉究抓,可能還需要記一下蒿柳。總的來說還是相信自己能出成果的漩蟆,但是前路長且阻,加油妓蛮。感謝花花怠李,感謝生信星球。
安裝加載R包
options("repos" = c(CRAN="http://mirrors.tuna.tsinghua.edu.cn/CRAN/"))
options(BioC_mirror="http://mirrors.ustc.edu.cn/bioc/")
install.packages("dplyr")
library(dplyr)
dplyr包的幾個基本函數(shù)
示例test <- iris[c(1:2,51:52,101:102),]
添加新列mutate()
mutate(test, new = Sepal.Length * Sepal.Width)
篩選列select()
select(test,c(1,5))#按列號篩選
select(test, Petal.Length, Petal.Width)#按列名篩選
篩選行filter()
filter(test, Species %in% c("setosa","versicolor"))
排序arrange()
arrange(test, Sepal.Length)#默認從小到大排序
arrange(test, desc(Sepal.Length))#用desc從大到小降序
匯總summarise()
結(jié)合group_by()
使用更佳
summarise(test, mean(Sepal.Length), sd(Sepal.Length))
group_by(test, Species)
summarise(group_by(test, Species),mean(Sepal.Length), sd(Sepal.Length))
幾個技巧
管道操作%>%
ctrl+shift+M(注意要切換英文輸入法),即將左邊元素的全部傳遞給右邊的函數(shù)蛤克。
統(tǒng)計unique值count(test,Species)
dplyr處理關(guān)系數(shù)據(jù)
內(nèi)連inner_join
inner_join(test1, test2, by = "x")
左連left_join
全連full_join
半連接semi_join
反連接anti_join
簡單合并
bind_rows() - rbind()
bind_cols() - cbind()
代碼和第一個類似
思維導(dǎo)圖
頭孢菌素