Я пытаюсь перебрать элементы из списка, в именах которых есть кавычки. До сих пор мне удалось следующее:
lm_uni1=matrix(nrow=100,ncol=2)
for(i in 5:100){
#t1.port.returns<-cbind(as.data.frame(stress.list$`item:i`[[1]]),
# as.data.frame(stress.list$`item:i`[[2]]),
# as.data.frame(stress.list$`item:i`[[3]]),
# as.data.frame(stress.list$`item:i`[[4]]))
#The above iteration does not work because the i is between ` ` and thus
#it does not change over the iteration process.
#The next one tries to adjust for the issue:
t1.port.returns<-cbind(
cat(paste("stress.list$`item:",i,"`[[1]]",sep="")),
cat(paste("stress.list$`item:",i,"`[[2]]",sep="")),
cat(paste("stress.list$`item:",i,"`[[3]]",sep="")),
cat(paste("stress.list$`item:",i,"`[[4]]",sep=""))
)
names(t1.port.returns)<-c("PortMU","PortS","PortA","PortN")
AnaDataset<-as.data.frame(cbind(t1.port.returns,FF))
names(AnaDataset)[6]<-"F5"
seq1<-summary(lm(PortMU~RF+F1+F2+F3+F4+F5,data=AnaDataset))
lm_uni1[i,1]<-seq1$coef[2,1]
lm_uni1[i,2]<-seq1$coef[2,4]
}
Однако t1.port.returns
возвращает следующее:
stress.list$`item:5`[[1]]stress.list$`item:5`[[2]]stress.list$`item:5`[[3]]stress.list$`item:5`[[4]]NULL
, который не является матрицей данных. Функция cat () не помогает в доступе к данным, связанным с именем элемента списка. Есть ли способ решить эту проблему?
Вывод одного из пунктов списков:
> head(stress.list$`item:50`[[1]])
[1] 0.0005571963 0.0007163872 0.0006470110 0.0007732345 0.0012316404 0.0010932486
> length(stress.list$`item:50`[[1]])
[1] 189
Таким образом, в основном вывод t1.port.returns
должен быть таким:
>head(cbind(stress.list$`item:50`[[1]],stress.list$`item:50`[[2]],stress.list$`item:50`[[3]]))
[,1] [,2] [,3]
[1,] 0.0005571963 0.0005476554 0.0007157594
[2,] 0.0007163872 0.0007142794 0.0007953541
[3,] 0.0006470110 0.0007206310 0.0006402598
[4,] 0.0007732345 0.0008514236 0.0009244147
[5,] 0.0012316404 0.0012356093 0.0013711927
[6,] 0.0010932486 0.0009898300 0.0012163905
но при реализации cat () для итерации мы не выводим вышеприведенный вывод.