我使用ExtremeBounds包,其提供作爲結果與多級列表(其中包括)在最低層dataframes深處列表。我在幾個規格運行此包,我想收集選定dataframes的一些列在了這些結果。這些應該由規範(SPEC1和SPEC2在下面的示例)被收集並佈置在dataframes的列表。 dataframes的這個列表然後可以用於所有類型的東西,例如不同規格的結果導出到不同的Excel表。R:ADRESS對象與內部功能/環(ExtremeBounds封裝)過濾命令
下面是一些代碼,創建有問題的對象(只需運行該代碼盲目的,我的問題只涉及如何處理那種它創建列表:eba_results):
library("ExtremeBounds")
Data <- data.frame(var1=rbinom(30,1,0.2),var2=rbinom(30,2,0.2),
var3=rnorm(30),var4=rnorm(30),var5=rnorm(30))
spec1 <- list(y=c("var1"),
freevars=c("var2"),
doubtvars=c("var3","var4"))
spec2 <- list(y=c("var1"),
freevars=c("var2"),
doubtvars=c("var3","var4","var5"))
indicators <- c("spec1","spec2")
ebaFun <- function(x){
eba <- eba(data=Data, y=x$y,
free=x$freevars,
doubtful=x$doubtvars,
reg.fun=glm, k=1, vif=7, draws=50, weights = "lri", family = binomial(logit))}
eba_results <- lapply(mget(indicators),ebaFun) #eba_results is the object in question
手動我知道如何訪問每一個元素,例如:
eba_results$spec1$bounds$type #look at str(eba_results) to see the different levels
因此,「邊界」是具有兩個SPEC1和SPEC2相同列名的數據幀。我想從 「邊界」 收集以下5列:
類型,cdf.mu.normal,cdf.above.mu.normal,cdf.mu.generic,cdf.above.mu.generic
爲每一個規格數據幀。手動,這是簡單的,但很醜:
collectedManually <-list(
manual_spec1 = data.frame(
type=eba_results$spec1$bounds$type,
cdf.mu.normal=eba_results$spec1$bounds$cdf.mu.normal,
cdf.above.mu.normal=eba_results$spec1$bounds$cdf.above.mu.normal,
cdf.mu.generic=eba_results$spec1$bounds$cdf.mu.generic,
cdf.above.mu.generic=eba_results$spec1$bounds$cdf.above.mu.generic),
manual_spec2= data.frame(
type=eba_results$spec2$bounds$type,
cdf.mu.normal=eba_results$spec2$bounds$cdf.mu.normal,
cdf.above.mu.normal=eba_results$spec2$bounds$cdf.above.mu.normal,
cdf.mu.generic=eba_results$spec2$bounds$cdf.mu.generic,
cdf.above.mu.generic=eba_results$spec2$bounds$cdf.above.mu.generic))
但我有2種以上規格的,我想這應該是可能的lapply功能於一身漂亮的方式。任何幫助,將不勝感激!
PS:一個普通的例子hrbrmstr的回答適用的,但它竟然是過於簡單化了:
exampleList = list(a=list(aa=data.frame(A=rnorm(10),B=rnorm(10)),bb=data.frame(A=rnorm(10),B=rnorm(10))),
b=list(aa=data.frame(A=rnorm(10),B=rnorm(10)),bb=data.frame(A=rnorm(10),B=rnorm(10))))
,我想有一個對象,收集,例如,所有的A和乙載體引入兩個數據幀(每個具有其各自的A和B),它們然後數據幀的列表。手動,這將是這樣的:
dfa <- data.frame(A=exampleList$a$aa$A,B=exampleList$a$aa$B)
dfb <- data.frame(A=exampleList$a$aa$A,B=exampleList$a$aa$B)
collectedResults <- list(a=dfa, b=dfb)
什麼是你想要的輸出了這一切? –
數據幀列表 –