Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 函数cut(xxx,“sec”不';不要正确地把时间缩短一秒_R_Cut - Fatal编程技术网

R 函数cut(xxx,“sec”不';不要正确地把时间缩短一秒

R 函数cut(xxx,“sec”不';不要正确地把时间缩短一秒,r,cut,R,Cut,当我使用cut(tmp$时间,“秒”)继续 time lasting elec 39 2013-04-18 13:06:25 8355222 -66.4 40 2013-04-18 13:06:25 8696122 -20.9 41 2013-04-18 13:06:27 9310817 -21.2 42 2013-04-18 13:06:25 9715650 -21.0 43 2013-04-18 13:06:26 338875 -29.6 结果表明 [1] 2013-04

当我使用cut(tmp$时间,“秒”)继续

       time lasting  elec
39 2013-04-18 13:06:25 8355222 -66.4
40 2013-04-18 13:06:25 8696122 -20.9
41 2013-04-18 13:06:27 9310817 -21.2
42 2013-04-18 13:06:25 9715650 -21.0
43 2013-04-18 13:06:26  338875 -29.6
结果表明

[1] 2013-04-18 13:06:25 2013-04-18 13:06:25 2013-04-18 13:06:27 2013-04-18 13:06:25
[5] 2013-04-18 13:06:25

但我认为[5]应该是2013-04-18 13:06:26。有什么问题吗?

这很好,您可能需要检查您的日期格式

library(lubridate)
df <- data.frame(time = ymd_hms(c('2013-04-18 13:06:25',
                                  '2013-04-18 13:06:25',
                                  '2013-04-18 13:06:27',
                                  '2013-04-18 13:06:25',
                                  '2013-04-18 13:06:26' )))

cut(df$time, "sec")

[1] 2013-04-18 13:06:25 2013-04-18 13:06:25 2013-04-18 13:06:27 2013-04-18 13:06:25
[5] 2013-04-18 13:06:26
Levels: 2013-04-18 13:06:25 2013-04-18 13:06:26 2013-04-18 13:06:27
库(lubridate)

df您必须使用dput(head(tmp))向我们显示数据
,这样我们就可以确切地知道它是什么样子了。我无法重现您的错误,一切似乎都是正确的。在输出中,您缺少由
cut
返回的因子级别。你能发布str(head(tmp))吗?