从 SPLUS 的 timeSpan class 到 R 的 POSIXlt class
From timeSpan class of SPLUS to POSIXlt class of R
我正在尝试将具有 timeSpan
class 的 SPLUS
数据转换为具有 POSIXlt
class 的 R
数据。我查看了 lubridate
包,但找不到解决方法。 R
无法检测到 timeSpan
class,因此当我尝试使用数据创建变量时它会报错。
lubridate
软件包帮助文件 ?'lubridate-package'
说
Lubridate distinguishes between moments in time (known as instants)
and spans of time (known as time spans, see Timespan-class). Time
spans are further separated into Duration-class, Period-class and
Interval-class objects.
我也从包开发者写的 article on lubridate
寻求帮助,但找不到解决它的方法。是否可以将SPLUS
的timeSpan
class转换成R
的posixlt
class?
SPLUS 数据:
"span" = new("timeSpan", .Data = list(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7,
7, 30, 30, 91, 91, 365, 1826, 9131, 36525),
c(1, 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 5000, 15000, 60000, 60000,
300000, 300000, 900000, 900000, 3600000, 10800000, 10800000, 21600000,
0, 0, 0, 37800000, 37800000, 27000000, 27000000, 21600000, 21600000,
21600000, 0)),
.Data.names = c("julian.day", "milliseconds"),
.Data.classes = new("CLASS",c("integer", "integer")),
format = "%dd %Hh %Mm %Ss %NMS")
在 SPLUS 上评估后的数据外观 workbench:
span
[1] 0d 0h 0m 0s 1MS 0d 0h 0m 0s 1MS 0d 0h 0m 0s 2MS
[4] 0d 0h 0m 0s 5MS 0d 0h 0m 0s 10MS 0d 0h 0m 0s 25MS
[7] 0d 0h 0m 0s 50MS 0d 0h 0m 0s 100MS 0d 0h 0m 0s 250MS
[10] 0d 0h 0m 0s 500MS 0d 0h 0m 1s 0MS 0d 0h 0m 5s 0MS
[13] 0d 0h 0m 15s 0MS 0d 0h 1m 0s 0MS 0d 0h 1m 0s 0MS
[16] 0d 0h 5m 0s 0MS 0d 0h 5m 0s 0MS 0d 0h 15m 0s 0MS
[19] 0d 0h 15m 0s 0MS 0d 1h 0m 0s 0MS 0d 3h 0m 0s 0MS
[22] 0d 3h 0m 0s 0MS 0d 6h 0m 0s 0MS 1d 0h 0m 0s 0MS
[25] 7d 0h 0m 0s 0MS 7d 0h 0m 0s 0MS 30d 10h 30m 0s 0MS
[28] 30d 10h 30m 0s 0MS 91d 7h 30m 0s 0MS 91d 7h 30m 0s 0MS
[31] 365d 6h 0m 0s 0MS 1826d 6h 0m 0s 0MS 9131d 6h 0m 0s 0MS
[34] 36525d 0h 0m 0s 0MS
R 控制台错误:
Error in getClass(Class, where = topenv(parent.frame())) :
“timeSpan” is not a defined class
从S对象中取出核心list
.Data
对象,然后可以将其操作成Rdifftime
,然后可以从added/subtracted POSIXct/lt
或 Date
对象:
out <- Reduce(`+`,
Map(as.difftime, Map(`/`, x, c(1,1000)), units=list("days","secs"))
)
units(out) <- "days"
round(out,4)
#Time differences in days
# [1] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
# [7] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001
#[13] 0.0002 0.0007 0.0007 0.0035 0.0035 0.0104
#[19] 0.0104 0.0417 0.1250 0.1250 0.2500 1.0000
#[25] 7.0000 7.0000 30.4375 30.4375 91.3125 91.3125
#[31] 365.2500 1826.2500 9131.2500 36525.0000
其中 x
是:
x <- list(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 7, 7, 30, 30, 91, 91, 365, 1826, 9131, 36525
), c(1, 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 5000, 15000,
60000, 60000, 3e+05, 3e+05, 9e+05, 9e+05, 3600000, 10800000,
10800000, 21600000, 0, 0, 0, 37800000, 37800000, 2.7e+07, 2.7e+07,
21600000, 21600000, 21600000, 0))
我正在尝试将具有 timeSpan
class 的 SPLUS
数据转换为具有 POSIXlt
class 的 R
数据。我查看了 lubridate
包,但找不到解决方法。 R
无法检测到 timeSpan
class,因此当我尝试使用数据创建变量时它会报错。
lubridate
软件包帮助文件 ?'lubridate-package'
说
Lubridate distinguishes between moments in time (known as instants) and spans of time (known as time spans, see Timespan-class). Time spans are further separated into Duration-class, Period-class and Interval-class objects.
我也从包开发者写的 article on lubridate
寻求帮助,但找不到解决它的方法。是否可以将SPLUS
的timeSpan
class转换成R
的posixlt
class?
SPLUS 数据:
"span" = new("timeSpan", .Data = list(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7,
7, 30, 30, 91, 91, 365, 1826, 9131, 36525),
c(1, 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 5000, 15000, 60000, 60000,
300000, 300000, 900000, 900000, 3600000, 10800000, 10800000, 21600000,
0, 0, 0, 37800000, 37800000, 27000000, 27000000, 21600000, 21600000,
21600000, 0)),
.Data.names = c("julian.day", "milliseconds"),
.Data.classes = new("CLASS",c("integer", "integer")),
format = "%dd %Hh %Mm %Ss %NMS")
在 SPLUS 上评估后的数据外观 workbench:
span
[1] 0d 0h 0m 0s 1MS 0d 0h 0m 0s 1MS 0d 0h 0m 0s 2MS
[4] 0d 0h 0m 0s 5MS 0d 0h 0m 0s 10MS 0d 0h 0m 0s 25MS
[7] 0d 0h 0m 0s 50MS 0d 0h 0m 0s 100MS 0d 0h 0m 0s 250MS
[10] 0d 0h 0m 0s 500MS 0d 0h 0m 1s 0MS 0d 0h 0m 5s 0MS
[13] 0d 0h 0m 15s 0MS 0d 0h 1m 0s 0MS 0d 0h 1m 0s 0MS
[16] 0d 0h 5m 0s 0MS 0d 0h 5m 0s 0MS 0d 0h 15m 0s 0MS
[19] 0d 0h 15m 0s 0MS 0d 1h 0m 0s 0MS 0d 3h 0m 0s 0MS
[22] 0d 3h 0m 0s 0MS 0d 6h 0m 0s 0MS 1d 0h 0m 0s 0MS
[25] 7d 0h 0m 0s 0MS 7d 0h 0m 0s 0MS 30d 10h 30m 0s 0MS
[28] 30d 10h 30m 0s 0MS 91d 7h 30m 0s 0MS 91d 7h 30m 0s 0MS
[31] 365d 6h 0m 0s 0MS 1826d 6h 0m 0s 0MS 9131d 6h 0m 0s 0MS
[34] 36525d 0h 0m 0s 0MS
R 控制台错误:
Error in getClass(Class, where = topenv(parent.frame())) :
“timeSpan” is not a defined class
从S对象中取出核心list
.Data
对象,然后可以将其操作成Rdifftime
,然后可以从added/subtracted POSIXct/lt
或 Date
对象:
out <- Reduce(`+`,
Map(as.difftime, Map(`/`, x, c(1,1000)), units=list("days","secs"))
)
units(out) <- "days"
round(out,4)
#Time differences in days
# [1] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
# [7] 0.0000 0.0000 0.0000 0.0000 0.0000 0.0001
#[13] 0.0002 0.0007 0.0007 0.0035 0.0035 0.0104
#[19] 0.0104 0.0417 0.1250 0.1250 0.2500 1.0000
#[25] 7.0000 7.0000 30.4375 30.4375 91.3125 91.3125
#[31] 365.2500 1826.2500 9131.2500 36525.0000
其中 x
是:
x <- list(c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 7, 7, 30, 30, 91, 91, 365, 1826, 9131, 36525
), c(1, 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 5000, 15000,
60000, 60000, 3e+05, 3e+05, 9e+05, 9e+05, 3600000, 10800000,
10800000, 21600000, 0, 0, 0, 37800000, 37800000, 2.7e+07, 2.7e+07,
21600000, 21600000, 21600000, 0))