相关疑难解决方法(0)

为什么reshape2熔化返回值= NA?

为什么reshape2 melt返回value= NA我吗?

它可以重塑,但不是reshape2:

这是一个示例数据文件:

"","station_id","year","month","day","h1","h2","h3","h4","h5","h6","h7","h8","h9","h10","h11","h12","h13","h14","h15","h16","h17","h18","h19","h20","h21","h22","h23","h24"
"1",1,2004,1,1,46,46,45,41,39,35,33,33,36,47,53,54,55,55,55,55,52,46,40,40,39,38,40,41
"2",1,2004,1,2,43,44,46,46,47,47,47,47,47,47,47,49,52,56,54,56,57,53,50,47,46,45,45,45
"3",1,2004,1,3,45,46,46,44,43,46,46,47,51,55,56,59,65,68,69,68,68,65,64,63,62,63,63,62
"4",1,2004,1,4,63,62,62,62,60,60,60,62,60,64,64,66,71,70,71,72,71,68,67,67,65,64,65,64
"5",1,2004,1,5,64,63,65,64,64,64,64,64,65,66,66,67,68,68,66,66,66,66,63,54,52,49,47,47
"6",1,2004,1,6,47,46,45,43,41,41,39,39,40,43,45,44,45,46,46,46,45,39,39,39,38,36,32,32
Run Code Online (Sandbox Code Playgroud)

让我们说它保存为/tmp/foo.csv,然后:

使用重塑:

$ R
...
Type 'q()' to quit R.

> library("reshape")
Loading required package: plyr

Attaching package: ‘reshape’

The following object(s) are masked from ‘package:plyr’:

    rename, round_any

> hlist <- NULL; for(z in 1:24) { hlist <- cbind(hlist, sprintf("h%d",z)) }
> 
> thh <- read.csv('/tmp/foo.csv')
> thm <- melt(thh,measure.vars=hlist,variable="hour")
> head(thm)
  station_id year month day hour value
1          1 2004     1 …
Run Code Online (Sandbox Code Playgroud)

r reshape2

3
推荐指数
1
解决办法
963
查看次数

标签 统计

r ×1

reshape2 ×1