我想知道以下函数中错误的原因和可能的解决方案。索引到数据帧会产生错误,而直接应用该函数则不会。在我看来是索引相关但无法弄清楚为什么或如何索引数据框而不产生上述错误。
z2p <-c(23.20,20.40,20.66,20.52,20.82,21.46,21.58,22.06,22.24,23.10,23.76,24.20,25.42,28.90,31.60,31.62,27.84,29.90,29.38,30.16,30.78,33.54,37.20,44.90,45.90,46.96,52.26,46.84,40.16,39.86,42.96,45.02,47.00,43.00,47.58,47.02,49.40,46.36,44.80,42.54,40.06,37.12,37.30,37.30,36.60,32.92,28.80,36.40,38.32,37.72,35.20,36.50,38.26,41.40,42.06,43.48,47.08,45.00,46.78,43.52,45.50,45.44,46.00,45.92,46.24,46.60,47.08,46.66,50.50,49.06,48.50,47.38,48.66,49.44,44.68,45.74,48.80,49.30,49.20,48.22,48.46,44.48,41.30,42.74,46.64,47.48,48.60,48.06,50.60,49.92,51.85,56.02,56.30,59.62,62.66,62.22,62.38,59.44,59.10,57.88,57.88,57.42,56.08,55.60,58.72,59.88,60.30,57.12,55.96,56.20,55.67,55.64,55.52,54.62,56.30,59.10,58.71,58.64,57.76,60.24,59.04,61.38,60.86,60.94,64.07,63.48,70.30,71.10,73.32,73.35,70.46,72.80,72.56,72.50,72.10,72.08,77.80,79.04,88.28,93.80,94.72,91.00,93.78,89.46,89.14,89.96,80.24,76.58,78.04,87.90,76.80,69.98,64.28,59.78,51.28,56.40,61.30,59.44,57.91,63.61,65.72,66.46,65.66,67.06,65.72,76.43,80.13,81.27,77.00,70.55,79.69,78.12,78.78,82.68,79.56,79.68,80.11,81.75,87.28,83.63,83.30,79.07,77.39,74.17,73.00,71.04,77.86,78.76,76.30,78.37,78.45,81.15,80.45,79.36,83.33,84.84,84.34,88.20,86.35,88.08,89.70,96.93,102.16,104.20,106.32,114.07,111.92,115.87,111.22,113.51,115.09,116.53,118.56,111.60,115.78,124.97,128.85,128.34,126.56,125.43,137.25,137.92)
wavelet<- c("d2","s2")
nlevel <- seq(1: as.integer (floor (logb ((length(z2p)),base=2))))
library(wmtsa)
w4 <- expand.grid ( wavelet = wavelet , nlevels = nlevel , stringsAsFactors = FALSE )
se <- seq ( nrow ( w4 ) )
fun <- function ( i ) wavMODWT ( z2p , wavelet = w4[,1][i] , n.levels = w4[,2][i] )
DWT <- lapply( se , fun )
# the same results occur as below when using the $ sign
str(DWT[[1]])
#List of 6
$ data : Named num [1:222] -57.36 -1.4 0.13 -0.07 0.15 ...
..- attr(*, "names")= chr [1:222] "d1(0)" "d1(1)" "d1(2)" "d1(3)" ...
$ scales : Named num [1:222] 80.6 21.8 20.5 20.6 20.7 ...
..- attr(*, "names")= chr [1:222] "s1(0)" "s1(1)" "s1(2)" "s1(3)" ...
$ series :Error in `[[.wavTransform`(object, i) :
Index must be on the interval [1,2]