我試圖子集矩陣:在其他基質由值子集的矩陣
windowSize <- 60
windows <- embed(1:nrow(datatsr), windowSize)
head(windows):
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18]
[1,] 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43
[2,] 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44
[3,] 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45
[4,] 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46
[5,] 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47
[6,] 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48
dim(windows)
[1] 3291 60
的值(其中V1
列實際上是行號我想在windows
矩陣包括以上):
頭(子集):
V1
1 67
2 89
3 111
4 133
5 155
6 176
dim(subset)
[1] 152 1
range(subset)
[1] 67 3351
我想輸出矩陣只包含存在於的V1列中的行數矩陣,而不是其他行。
在例如:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [,16] [,17] [,18]
[1,] 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109
其中subset[,1]
所述第一值是從126到109的序列 - 即存在於windows
矩陣的67'th行中的序列。等等...
我想:
window=windows[subset[,1],]
Error: subscript out of bounds
或:
window=subset(windows,windows%in%subset[,1])
Error in subset.matrix(windows, windows %in% subset[, 1]) :
(subscript) logical subscript too long
我在做什麼錯?
我不能告訴你,你在做什麼錯了,因爲你沒有提供足夠的信息。建立一個小例子,看看它出錯的地方....或提供關於這些對象的維度的足夠信息。 –
當然,完成了。 – user1665355
仍然沒有足夠的信息。 –