【发布时间】:2017-04-18 16:44:28
【问题描述】:
在我的脚本中,我已经转换了这个 data.frame,如下所示:
df.modified<-transform(df, new.col= Payment.date-Selectionfinal$Invoice.Date)
这是结果:
Client.Code. Invoice.Date Payment.date new.col
1: 1004850 2016-01-31 2016-11-22 296 days
2: 1004850 2016-06-30 2016-11-22 145 days
3: 1004850 2016-06-30 2016-11-22 145 days
4: 1004850 2016-06-30 2016-11-22 145 days
5: 1004850 2016-09-30 2016-11-22 53 days
然后,我需要将其绘制成直方图,但我有这个问题:
> hist(df.modified[,c(4)])
Error in hist.default(Completo[, c(4)]) : 'x' must be numeric
这是我的 df 的 str:
$ Client.Code.: int 1004850 1004850 1004850 1004850 1004850 1004850 1004850 1004874 1004874 1005133 ...
$ Invoice.Date: Date, format: "2016-01-31" "2016-06-30" "2016-06-30" "2016-06-30" ...
$ Payment.date: Date, format: "2016-11-22" "2016-11-22" "2016-11-22" "2016-11-22" ...
$ new.col :Class 'difftime' atomic [1:4430] 296 145 145 145 53 53 53 102 72 71 ...
我想知道其中的诀窍。谢谢。
【问题讨论】:
-
hist(as.numeric(df.modified[,c(4)])) -
我以前试过这个:(> hist(as.numeric(df.modified[,c(4)])) 错误在 hist(as.numeric(df.modified[, c(4) ])) : (list) 对象不能被强制输入 'double')
-
@ÁlvaroRodríguez 你还需要解决这个问题吗?