和Python对应,用R如何清理数据呢?
R主要用到两个包:tidyr
和dplyr
library(tidyr)
?gather
?spread

一、单独表的“长宽互变”
依旧按场景来看。
(一)“省份—年份”式

gather(pf, 'year', 'n', 2:4)

(二)“省份—分类”式

spread(pf, size, amount)

(三)时间式
类似时间这样的数据分割和合并


二、多表的“增宽加长”








和Python对应,用R如何清理数据呢?
R主要用到两个包:tidyr
和dplyr
library(tidyr)
?gather
?spread
依旧按场景来看。
gather(pf, 'year', 'n', 2:4)
spread(pf, size, amount)
类似时间这样的数据分割和合并
本文标题:用R处理数据的结构性问题
本文链接:https://www.haomeiwen.com/subject/cfwyvftx.html
网友评论