[英]cbind in time-series data
Here is a simple example that works fine: 这是一个可以正常工作的简单示例:
a = 1; b = 2; c = 3
d = 65; e = 66; f = 77
m1 = cbind(a, b, c); m2 = cbind(d, e, f); M = cbind(m1, m2)
colnames(M)
# [1] "a" "b" "c" "d" "e" "f"
But, now try exactly the same thing with time-series data: 但是,现在尝试对时序数据进行完全相同的操作:
a = 1; b = 2; c = 3
d = 65; e = 66; f = 77
m1 = as.ts(cbind(a, b, c)); m2 = as.ts(cbind(d, e, f)); M = cbind(m1, m2)
colnames(M)
# [1] "m1.a" "m1.b" "m1.c" "m2.d" "m2.e" "m2.f"'
How do I avoid these prefixes for time series data? 如何避免时间序列数据使用这些前缀?
(ie: the prefixes m1.
and m2.
) (即:前缀
m1.
和m2.
)
PS: Obviously I know we can just do a direct "cbind" command on a, b, c, d, e, f
bypassing m1
and m2
, but I need these intermediate staged matrices in a loop. PS:显然,我知道我们可以绕过
m1
和m2
在a, b, c, d, e, f
上执行直接的“ cbind”命令,但是我需要循环使用这些中间阶段矩阵。
Can't explain why, but cbind.data.frame
works the same for both: 无法解释原因,但是
cbind.data.frame
对两者都起作用:
a = 1; b = 2; c = 3
d = 65; e = 66; f = 77
m1 = cbind(a, b, c)
m2 = cbind(d, e, f)
M = cbind.data.frame(m1, m2)
colnames(M)
#[1] "a" "b" "c" "d" "e" "f"
m1 = as.ts(cbind(a, b, c))
m2 = as.ts(cbind(d, e, f))
M = cbind.data.frame(m1, m2)
colnames(M)
#[1] "a" "b" "c" "d" "e" "f"
There's no way to prevent cbind.ts
from doing this. 无法阻止
cbind.ts
执行此操作。 The usual way you would prevent it would be to set deparse.level=0
, but cbind.ts
ignores it. 您可以防止的通常方法是设置
deparse.level=0
,但是cbind.ts
忽略它。
R> stats:::cbind.ts
function (..., deparse.level = 1)
{
if (deparse.level != 1)
.NotYetUsed("deparse.level != 1")
.cbind.ts(list(...), .makeNamesTs(...), dframe = FALSE, union = TRUE)
}
<bytecode: 0x35531f8>
<environment: namespace:stats>
You can always set the colnames
yourself, just be careful they are "valid" (eg via make.names
) and not duplicated, or you might have issues later in your analysis. 您始终可以自己设置
colnames
,只是要小心它们是“有效的”(例如,通过make.names
)并且不能重复,否则您稍后的分析中可能会遇到问题。
colnames(M) <- make.names(c(colnames(m1), colnames(m2)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.