99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
2018-10-18 閱讀量: 1319
干貨!用R數(shù)據(jù)預(yù)處理dplyr包函數(shù)的整理

簡介:dplyr是R語言中使用頻次非常高的一個(gè)包,主要用來對數(shù)據(jù)進(jìn)行預(yù)處理,靈活、強(qiáng)大,是Rer必須掌握的一個(gè)包。


常用函數(shù)

  • arrange
  • select
  • tbl_df
  • between
  • bind
  • case_when
  • count
  • desc
  • do
  • filter
  • first
  • groups
  • group_by
  • if_else
  • inner_join
  • join
  • left_join
  • last
  • matches
  • mutate
  • mutate_if
  • n
  • select
  • summarise
  • tbl
  • transmute


selectselect函數(shù)可以選取指定的對象中的列數(shù)據(jù)

#下面我們通過使用select函數(shù)來選取finance.data中的幾列數(shù)據(jù)#選取一列finance.data.select <- head(select(finance.data,證券代碼))#選取兩列及以上finance.data.select <- head(select(finance.data,證券代碼,roe_ma))當(dāng)然,除此之外,還可以使用start_with,end_with,contains,matches函數(shù)來配合select函數(shù)一起使用


#配合start_with函數(shù),可以選取任意字符開頭的列finance.data.select <- head(select(finance.data, starts_with("o")))#配合end_with函數(shù),可以選取任意字符結(jié)尾的列finance.data.select <- head(select(finance.data, starts_with("g")))#配合contains函數(shù),可以選取包含任意字符的列finance.data.select <- head(select(finance.data, contains("o")))#配合matches函數(shù),可以選取符合正則規(guī)則的列finance.data.select <- head(select(finance.data, matches("g")))


filterfilter是一個(gè)過濾函數(shù),通過這個(gè)函數(shù)可以篩選出符合條件的數(shù)據(jù)。


#首先選取finance.data中的兩列finance.data.select <- select(finance.data,證券代碼,roe_ma)#使用filter函數(shù)保留roe_ma列中大于15以上的行finance.data.select <- filter(finance.data.select,? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?finance.data.select

betweenbetween主要篩選介于兩個(gè)值之間的數(shù)據(jù)。



#判斷roe_ma的值介于17和18之間finance.data.select


case_whencase_when在對數(shù)據(jù)重編碼情況下經(jīng)常用到。


if_elseif_else類似excel中的if函數(shù),類似R基礎(chǔ)包中的ifelse函數(shù),唯一不同的是,if_else中包含一個(gè)對缺失值處理的參數(shù)。

#首先選取finance.data中的兩列finance.data.select <- select(finance.data,證券代碼,roe_ma)finance.data.select <- tbl_df(finance.data.select)#使用if_elsefinance.data.select


arrangearrange函數(shù)使用desc函數(shù)來對數(shù)據(jù)排序。



0.0000
1
關(guān)注作者
收藏
評論(0)

發(fā)表評論

暫無數(shù)據(jù)
推薦帖子