У меня есть набор данных, который выглядит так, где первая строка - это время до погашения, а первый столбец - это даты, а остальные данные - это доходность к погашению
И я пытаюсь получить результат, который выглядит так
Рисунок 2
Я пробовал этот код
dput(yields)
x = yields[,1]
y = yields[,1]
z.matrix = matrix(nrow=nrow(yield),ncol=ncol(yield)-1)
for(i in 2:nrow(yields)){
for(j in 2:(ncol(yields))-1){
z.matrix[i,j] = yield[i,j+1]
}
}
lines3D(x, y, z.matrix)
И это дает мне ошибку: Ошибка в scatter3D (x, y, z, type = "l"): 'z' должно иметь такая же длина, как у 'x'
Data
yield <- structure(list(Date = structure(c(1186444800, 1186531200, 1186704000,
1186963200, 1187049600, 1187136000, 1187222400, 1187308800, 1187568000,
1187654400, 1187740800, 1187827200, 1187913600, 1188172800, 1188259200,
1188345600, 1188432000, 1188518400), class = c("POSIXct", "POSIXt"
), tzone = ""), X1 = c(9.064326, 8.969148, 9.128214, 9.084583,
9.088544, 9.080606, 9.0806, 9.116042, 9.080283, 9.108036, 9.084211,
9.052445, 9.025128, 8.985457, 9.001349, 9.041063, 9.10459, 9.1453
), X2 = c(9.085159, 8.974176, 9.12059, 9.069715, 9.074333, 9.065076,
9.065069, 9.063908, 9.022211, 9.054573, 9.026792, 8.98975, 8.961298,
8.915039, 8.93357, 8.979879, 9.053955, 9.108225), X3 = c(9.092103,
8.975852, 9.118049, 9.064759, 9.069596, 9.0599, 9.059893, 9.04653,
9.002854, 9.036752, 9.007653, 8.968852, 8.940021, 8.891566, 8.910977,
8.959485, 9.037077, 9.095866), X4 = c(9.095575, 8.97669, 9.116779,
9.06228, 9.067227, 9.057312, 9.057304, 9.037841, 8.993176, 9.027841,
8.998083, 8.958403, 8.929383, 8.87983, 8.89968, 8.949287, 9.028638,
9.089687), X5 = c(8.712932, 8.589395, 8.697863, 8.644162, 8.648045,
8.631554, 8.627667, 8.612026, 8.568135, 8.601243, 8.582759, 8.554589,
8.52482, 8.482284, 8.506829, 8.542759, 8.619769, 8.689999), X6 = c(8.434263,
8.308453, 8.396236, 8.346351, 8.350531, 8.330447, 8.324888, 8.313128,
8.272898, 8.305936, 8.296262, 8.277004, 8.247676, 8.212734, 8.241364,
8.268976, 8.345336, 8.422634), X7 = c(8.336248, 8.210243, 8.291891,
8.245112, 8.249981, 8.229292, 8.223777, 8.213829, 8.176592, 8.21018,
8.203927, 8.188092, 8.159478, 8.12425, 8.154651, 8.180216, 8.261256,
8.341228), X8 = c(8.273279, 8.1353, 8.225183, 8.178188, 8.182844,
8.155566, 8.155586, 8.145378, 8.107947, 8.141237, 8.129704, 8.114724,
8.086003, 8.054416, 8.085064, 8.109359, 8.186472, 8.273313),
X9 = c(8.191452, 8.038108, 8.139739, 8.093593, 8.098358,
8.063096, 8.070529, 8.060409, 8.023834, 8.057133, 8.039449,
8.02588, 7.997401, 7.973722, 8.004988, 8.028113, 8.098592,
8.193915), X10 = c(8.221355, 8.077147, 8.161721, 8.108735,
8.113671, 8.087388, 8.08849, 8.046466, 7.996082, 8.016449,
8.016074, 7.999181, 7.970623, 7.939173, 7.968862, 8.002119,
8.078266, 8.169324), X11 = c(8.2263, 8.078335, 8.161404,
8.112908, 8.117761, 8.092432, 8.092793, 8.054483, 7.992561,
7.990581, 7.996326, 7.978963, 7.950399, 7.912756, 7.942222,
7.97596, 8.052297, 8.131317), X12 = c(8.207767, 8.051721,
8.135504, 8.08867, 8.093407, 8.063494, 8.063692, 8.035332,
7.972779, 7.962561, 7.966783, 7.951584, 7.925428, 7.886104,
7.920345, 7.95155, 8.02782, 8.100873), X13 = c(8.181, 8.016,
8.101, 8.054, 8.059, 8.023, 8.02, 8.005, 7.947, 7.935, 7.935,
7.923, 7.9, 7.861, 7.901, 7.929, 8.006, 8.076)), row.names = c(NA,
18L), class = "data.frame")