« 回覆文章 #2 於: 四月 11, 2017, 02:07:31 am »
管道函數
res_tidy %>%
arrange(p.adjusted) %>%
head(20) %>%
inner_join(grch38, by=c("gene"="ensgene")) %>%
select(gene, estimate, p.adjusted, symbol, description) %>%
pander::pandoc.table(split.table=100, justify="lrrll", style="rmarkdown")
通常來說,可以把“%>%”讀作then,即然後
一般:
> f1=function(x)sum(abs(round(x)))
管道函數
> f2=. %>% round %>% abs %>% sum
filter篩選
Example:iris資料集中Species不等於setosa和virginica,且Sepal.Width大於等於3.2.
> iris%>%filter(!Species%in%c("setosa","virginica"),Sepal.Width>=3.2)
arrange排序
arrange可以根據變數名依次對資料框進行排序,靠前的變數優先順序越高,對變數名使用desc函數即為倒序。
在R的base中,可以使用order來實現相同功能。
> arrange(mtcars, cyl, disp)%>%head(3)
> arrange(mtcars, desc(disp))%>%head(3)
select變數選擇
這裡的select在某種程度上也類似於SQL中的select,其功能是按變數名選擇資料欄變數。
> select(mtcars,mpg,cyl,carb)%>%head(3)
inner_join 返回所有在y中能查找到的x的行,且包含x和y的所有列;