Вопрос

I am struggling with extracting members from lists. The code shown below produces a list of 5 members with each member having a (sub)list of two members. I would like to extract the first members of each sub-list i.e (W1 and V1). How do I do this?

library(wavelets)

library(fGarch)

x<-rnorm(32)

spec.c <- garchSpec(model = list(omega=0.99, alpha=0.005, beta=0.005))

sim <- replicate(5, dwt(cumsum(garchSim(spec.c, n = 32)), filter="haar", 
                                    n.levels=2, boundary="reflection"))

Many thanks.

Это было полезно?

Решение

Try this...

W <- lapply( sim , function(x) `@`( x , W)[[1]] )
V <- lapply( sim , function(x) `@`( x , V)[[1]] )

You'll get a list of the first W of each of the 5 top-level lists and the first V of each of the 5 top-level lists.

The @ operator is used to access named slots in an S4 type object.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top