将ff POSIXct向量转换为ff数值向量

时间:2014-06-30 11:22:29

标签: r posixct ff

我正在尝试将带有 POSIXct 条目的 ff 向量转换为 ff 数字向量,其中包含自01-01-1970起源后的相应秒数。

x = as.ff(as.POSIXct(c("2014-06-30 00:01:27 BST", "2014-06-30 00:02:17 BST")))

自然' as.numeric(x)不起作用,产生:numeric(0)

as.ff(as.numeric(x[]))有效,屈服于

ff (open) double length=2 (2) [1] [2] 1398898887 1398898937

这是理想的结果。虽然它涉及ram对象x[]。有没有办法只使用ff对象来实现上述结果(即不介入ff向量的ram等价物?)

1 个答案:

答案 0 :(得分:0)

require(ff)
x = as.ff(as.POSIXct(c("2014-06-30 00:01:27 BST", "2014-06-30 00:02:17 BST")))
## Either clone it (creates a duplicate of the ff file)
done <- clone(x, ramclass = "numeric", ramattribs = list())
done[]
[1] 1404079287 1404079337
attr(,"class")
[1] "numeric"

## Or just modify the ramclass and ramattribs (see ?virtual: virtual(x))
virtual(x)$ramclass <- NULL
virtual(x)$ramattribs <- NULL
x[]
[1] 1404079287 1404079337

## And wrap this up in your own function