R - Reshape - Melt Error

后端 未结 2 1770
甜味超标
甜味超标 2021-01-27 09:50

I am trying to melt a data frame and I get this weird error. Any ideas why?

str(zx7)
\'data.frame\':   519 obs. of  5 variables:
 $ calday.new: Date, format: \"2         


        
2条回答
  •  后悔当初
    2021-01-27 10:01

    I don't konw how did you create your structure, but when I do this , it works for me

    zx7 <- data.frame( calday.new=seq(from = as.Date('2011-01-03'),by=1,length.out=519),
                       A20=ts(rep(0,519)),
                       B20=ts(rep(0,519)),
                       C20=ts(rep(0,519)),
                       D20=ts(rep(0,519)))
    

    I create the same structure as above :

    str(zx7)
    'data.frame':   519 obs. of  5 variables:
     $ calday.new: Date, format: "2011-01-03" "2011-01-04" "2011-01-05" ...
     $ A20       : Time-Series  from 1 to 519: 0 0 0 0 0 0 0 0 0 0 ...
     $ B20       : Time-Series  from 1 to 519: 0 0 0 0 0 0 0 0 0 0 ...
     $ C20       : Time-Series  from 1 to 519: 0 0 0 0 0 0 0 0 0 0 ...
     $ D20       : Time-Series  from 1 to 519: 0 0 0 0 0 0 0 0 0 0 ...
    

    Then I melt :

    head(melt(zx7, id=c("calday.new")))
      calday.new variable value
    1 2011-01-03      A20     0
    2 2011-01-04      A20     0
    3 2011-01-05      A20     0
    4 2011-01-06      A20     0
    5 2011-01-07      A20     0
    6 2011-01-08      A20     0
    

提交回复
热议问题