2013-03-20 26 views
0

這是我之前(有人回答)關於從多輸出函數提取特定輸出的問題的一種跟蹤。我已經成功地調用了簡單輸出,就像summary()調用的意思一樣,但是我很難按照類似的方法從fitdistr()函數中提取輸出。來自輸出(提取)的多個級別名稱

例如,當我運行「正常」的發行此功能,輸出爲均值和標準差:

> storage<-fitdistr((as.numeric(diameter.bin[[1]]$Strength)),"normal") 

>  storage 
     mean   sd  
>0.81428910  0.89574658 

>(0.04360426) (0.03083287) 

當我查找(我使用Rstudio,我可以看看存儲的變量/矩陣等)究竟存放在我的「存儲」的變量,我得到這個:

structure(list(estimate = structure(c(0.814289099526066, 0.89574657988675 
), .Names = c("mean", "sd")), sd = structure(c(0.0436042612645108, 
0.0308328688287655), .Names = c("mean", "sd")), vcov = structure(c(0.00190133160042372, 
0, 0, 0.00095066580021186), .Dim = c(2L, 2L), .Dimnames = list(
c("mean", "sd"), c("mean", "sd"))), n = 422L, loglik = -552.330814327093), .Names = c("estimate", "sd", "vcov", "n", "loglik"), class = "fitdistr") 

我希望做的是提取物只是平均值(列下的第一個項目「的意思是」,而不是一個在括號內)。我試過以下內容:

> test<-storage["estimate"] 

> test 

>$estimate 
>  mean  sd 

>0.8142891 0.8957466 

所以我可以成功地拉起第一行數據。現在我堅持只提取平均值。我存儲的變量'test',看起來應該有名字'mean'和'sd',實際上沒有名字可以調用。這裏是保存在我的 '測試' 變量:

結構(列表(估計=結構(C(0.814289099526066,0.89574657988675 ),.Names = C( 「中庸」, 「SD」))) .Names =「estimated」)

我可以看到實際上名稱「mean」和「sd」是我測試變量的一部分,但我似乎無法訪問它們。當我嘗試:

> names(test) 

>[1] "estimate" 

> test["mean"] 

>$< N A > 

>NULL 

人有怎麼去名字的這等「水平」訪問一個想法,我將不勝感激!

+1

你對[相對於[[for名單。 – mnel 2013-03-20 06:42:08

回答

3

當您感到困惑時,請使用str來獲取對象的正確結構。

str(storage) 
List of 5 
$ estimate: Named num [1:2] 0.814 0.896 
    ..- attr(*, "names")= chr [1:2] "mean" "sd" 
$ sd  : Named num [1:2] 0.0436 0.0308 
    ..- attr(*, "names")= chr [1:2] "mean" "sd" 
$ vcov : num [1:2, 1:2] 0.001901 0 0 0.000951 
    ..- attr(*, "dimnames")=List of 2 
    .. ..$ : chr [1:2] "mean" "sd" 
    .. ..$ : chr [1:2] "mean" "sd" 
$ n  : int 422 
$ loglik : num -552 
- attr(*, "class")= chr "fitdistr" 

均值和標準差都在估計varaible,我看到一個$下一估計,所以我這樣做

storage$estimate 
    mean  sd 
0.8142891 0.8957466 

然後我做

storage$estimate[1] 

或者

storage$estimate['mean'] 

    mean 
0.8142891