R-dplyr包使用的小總結(jié)

1、如果調(diào)用了兩個(gè)包,都有同樣的函數(shù),比如raster和dplyr都有select,就用dplyr::select


2、可以找出管道通道操作+contains、starts_with、ends_with

edu<-edu %>% select(contains("edu18"))


3、利用管道操作刪樣本

people<-sam[-which(sam$SAMPLEID%in%c("N130")),]


4、mutate操作(替換、新增變量超方便)

edu<-mutate(edu,EDU_UPDATE=ifelse(EDU_UPDATE==8,NA,EDU_UPDATE))


5、merge函數(shù)

edu<-merge(edu, place, by='SAMPLEID',all.x=TRUE)


6、!!、quo、unquo、!!!

詳見vignette(“dplyr-programming”)

###兩件事:(1)We need to quote the input ourselves;

(2)you use `!!` to say that you want to unquote an input so that it's evaluated, not quoted.

my_summarise <- function(df, group_var) {

??df %>%group_by(!!?group_var) %>% #!!你想要取消輸入的引號(hào),以便對(duì)其進(jìn)行評(píng)估

???????summarise(a = mean(a))}

my_summarise(df, quo(g1))

###`!!!` takes a list of elements and splices them into to the current call.

args <- list(na.rm = TRUE, trim = 0.25)

quo(mean(x, !!!?args))

args <- list(quo(x), na.rm = TRUE, trim = 0.25)

quo(mean(!!! args))


7、quo、unquo、!!!group分組+分組統(tǒng)計(jì)頻數(shù)和百分比

fangyuan<-interviewer%>%group_by(編碼)%>%summarise(n=n(),percentage=sum(反饋內(nèi)容新)/sum(反饋內(nèi)容總))

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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