I am trying to convert an ff vector with POSIXct entries to an ff numeric vector, containing the respective number of seconds since the origin 01-01-1970.
x = as.ff(as.POSIXct(c("2014-06-30 00:01:27 BST", "2014-06-30 00:02:17 BST")))
The 'natural' as.numeric(x)
does not work, yielding: numeric(0)
.
as.ff(as.numeric(x[]))
works, yielding
ff (open) double length=2 (2)
[1] [2]
1398898887 1398898937
which is the desirable outcome. Albeit, it involves the ram object x[]
. Is there a way to achieve the above result employing ff objects only (i.e. not intermediating the ram equivalent of the ff vector)?
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