- R包的小抄
- R包:tidyr
- 功能:【data clean】
- (1)數(shù)據(jù)框的變形
- (2)處理數(shù)據(jù)框中的空值
- (3)根據(jù)一個(gè)表格衍生出其他表格
- (4)實(shí)現(xiàn)行或列的分割和合并
- key-value--“鍵值對(duì)” ,表示一種對(duì)應(yīng)關(guān)系著榴。
- Reshape Data
- (1). gather() moves column names into a key column, gathering the column values into a singel value column. 簡(jiǎn)而言之:excel->spss
- gather(數(shù)據(jù)框名,需合并的列名(2個(gè))驻谆,合并后的key列名,value列名
- eg: 三條命令運(yùn)行結(jié)果一致
gather(a,X1999,X2000,key = "year",value = "cases")
gather(a,"year","cases",-country) #-country的意思就是合并除country外剩下的列庆聘。
gather(a, "year","cases",X1999,X2000)
- eg: 三條命令運(yùn)行結(jié)果一致
- gather(數(shù)據(jù)框名,需合并的列名(2個(gè))驻谆,合并后的key列名,value列名
- (2). spread spss->excel
- (1). gather() moves column names into a key column, gathering the column values into a singel value column. 簡(jiǎn)而言之:excel->spss
- Handle Missing Values
- (1). 刪除含NA的整行
drop_na()
drop_na(數(shù)據(jù)框名胜臊,有NA的列名) - (2). 根據(jù)上一行的數(shù)值填充
fill()
fill(數(shù)據(jù)框名,有NA的列名) - (3). 空值填入特定數(shù)值
replace_na()
replace_na(數(shù)據(jù)框名伙判,要填的列名=要填的值)replace_na(X,list(X2=2))
- (1). 刪除含NA的整行
- Expand Tables 【沒(méi)懂otz】
- complete(把空值的位置補(bǔ)全)
complete(X,nesting(X1),fill=list(X2=5))
- expand(列出每列值所有可能的組合)
- complete(把空值的位置補(bǔ)全)
- 功能:【data clean】
今日信息量過(guò)載ing