我上周写了一些完美的代码。
我今天试图再次使用它。有问题的部分采用数据帧的子集,并将第2列的diff
和diffinv
应用于数据帧/矩阵的长度。
这是我的数据框:
dput(d)
structure(list(Tiempo = c(1158, 1158.2, 1158.4, 1158.6, 1158.8,
1159, 1159.2, 1159.4, 1159.6, 1159.8, 1160), UT1 = c(10500, 10500,
10499, 10499, 10499, 10499, 10498, 10498, 10498, 10498, 10497
), UT2 = c(8238, 8238, 8238, 8238, 8238, 8238, 8238, 8238, 8238,
8238, 8238), UT3 = c(16991, 16991, 16991, 16991, 16991, 16991,
16990, 16990, 16990, 16989, 16989), UT4 = c(17903, 17904, 17905,
17906, 17906, 17907, 17908, 17910, 17912, 17913, 17914), UT5 = c(16044,
16044, 16044, 16044, 16044, 16044, 16044, 16044, 16044, 16044,
16044), UT6 = c(16261, 16261, 16261, 16261, 16261, 16261, 16261,
16261, 16261, 16261, 16261), UT7 = c(17094, 17094, 17094, 17094,
17094, 17094, 17094, 17094, 17094, 17094, 17094), UT8 = c(19036,
19037, 19036, 19037, 19037, 19037, 19038, 19038, 19039, 19040,
19041), UT9 = c(15192, 15192, 15192, 15191, 15191, 15191, 15190,
15190, 15189, 15189, 15188), UT10 = c(7113, 7113, 7113, 7113,
7113, 7113, 7113, 7113, 7113, 7113, 7113), UT11 = c(3701, 3701,
3701, 3700, 3700, 3698, 3696, 3695, 3692, 3690, 3689), UT12 = c(11666,
11666, 11666, 11666, 11666, 11666, 11666, 11667, 11669, 11670,
11671), TR1 = c(15805, 15805, 15805, 15805, 15805, 15805, 15805,
15805, 15805, 15805, 15805), TR2 = c(13718, 13718, 13718, 13718,
13718, 13718, 13718, 13718, 13718, 13718, 13718), TR3 = c(19047,
19048, 19050, 19050, 19049, 19050, 19055, 19070, 19071, 19079,
19087), TR4 = c(15847, 15847, 15847, 15849, 15849, 15849, 15849,
15849, 15849, 15848, 15849), TR5 = c(21087, 21087, 21087, 21087,
21087, 21087, 21087, 21087, 21087, 21087, 21086), TR6 = c(11434,
11434, 11434, 11434, 11434, 11434, 11433, 11433, 11433, 11425,
11403), TR7 = c(15769, 15769, 15769, 15769, 15769, 15769, 15769,
15769, 15769, 15769, 15769), TR8 = c(16915, 16915, 16915, 16915,
16915, 16915, 16915, 16915, 16915, 16915, 16915), TR9 = c(15800,
15800, 15800, 15796, 15773, 15755, 15745, 15744, 15735, 15706,
15697), TR10 = c(14121, 14121, 14121, 14121, 14121, 14121, 14121,
14121, 14120, 14121, 14120), TR11 = c(18247, 18247, 18247, 18247,
18247, 18247, 18247, 18247, 18247, 18247, 18247), TR12 = c(10877,
10877, 10877, 10877, 10878, 10878, 10878, 10878, 10878, 10878,
10878)), .Names = c("Tiempo", "UT1", "UT2", "UT3", "UT4", "UT5",
"UT6", "UT7", "UT8", "UT9", "UT10", "UT11", "UT12", "TR1", "TR2",
"TR3", "TR4", "TR5", "TR6", "TR7", "TR8", "TR9", "TR10", "TR11",
"TR12"), row.names = 5791:5801, class = "data.frame")
我试图运行的代码是
dd<-data.frame(cbind(d$Tiempo,(diffinv(abs(diff(as.matrix(c[,2:length(d)])))))))
我收到了这个错误:
Error in c[, 2:length(d)] : object of type 'builtin' is not subsettable
此外,当我使用:
q<-c(1:25)
length(q)
[1] 25
q[4:length(q)]
[1] 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
正如它应该的那样工作。 我不知道发生了什么。我很感激一些帮助。
谢谢
答案 0 :(得分:2)
我认为你打算这样做:
d[,2:length(d)]