2017-10-06 7 views
1

str()は、lm()と他のモデリング関数によって返されるリストのリストなど、オブジェクトの構造を表示するのに便利ですが、出力が多すぎます。私はリスト要素とその構造のの名前だけを示す簡単なツリー図を作成するためのツールを探しています。Rオブジェクトの構造を示すグラフィックツリー図を作成

例えば、この例では、

data(Prestige, package="car") 
out <- lm(prestige ~ income+education+women, data=Prestige) 
str(out, max.level=2) 
#> List of 12 
#> $ coefficients : Named num [1:4] -6.79433 0.00131 4.18664 -0.00891 
#> ..- attr(*, "names")= chr [1:4] "(Intercept)" "income" "education" "women" 
#> $ residuals : Named num [1:102] 4.58 -9.39 4.69 4.22 8.15 ... 
#> ..- attr(*, "names")= chr [1:102] "gov.administrators" "general.managers" "accountants" "purchasing.officers" ... 
#> $ effects  : Named num [1:102] -472.99 -123.61 -92.61 -2.3 6.83 ... 
#> ..- attr(*, "names")= chr [1:102] "(Intercept)" "income" "education" "women" ... 
#> $ rank   : int 4 
#> $ fitted.values: Named num [1:102] 64.2 78.5 58.7 52.6 65.3 ... 
#> ..- attr(*, "names")= chr [1:102] "gov.administrators" "general.managers" "accountants" "purchasing.officers" ... 
#> $ assign  : int [1:4] 0 1 2 3 
#> $ qr   :List of 5 
#> ..$ qr : num [1:102, 1:4] -10.1 0.099 0.099 0.099 0.099 ... 
#> .. ..- attr(*, "dimnames")=List of 2 
#> .. ..- attr(*, "assign")= int [1:4] 0 1 2 3 
#> ..$ qraux: num [1:4] 1.1 1.44 1.06 1.06 
#> ..$ pivot: int [1:4] 1 2 3 4 
#> ..$ tol : num 1e-07 
#> ..$ rank : int 4 
#> ..- attr(*, "class")= chr "qr" 
#> $ df.residual : int 98 
... 

私はこのような何かを取得したいと思います:

enter image description here

これは私が私のファイルにファイルフォルダのためtreeから得るものに似ていますがシステム:

C:\Dropbox\Documents\images>tree 
Folder PATH listing 
Volume serial number is 2250-8E6F 
C:. 
+---cartoons 
+---chevaliers 
+---icons 
+---milestones 
+---minard 
    +---minard-besancon 

結果はeiグラフィック文字の場合は、treeまたは上の図のような実際のグラフィックです。このようなものはありますか?

+0

あなたは、このリンクを参照してくださいましたhttps://stackoverflow.com/questions/36094183/how-to-build-だろうから、これを取得する簡単な方法a-dendrogram-from-a-directory-tree? – amrrs

+0

私はこれを見ていませんでした。それは良い参考資料です。 – user101089

答えて

1

str出力が何かのような...

a <- capture.output(str(out, max.level=2)) 
a <- trimws(gsub("\\:.*", "", a[grepl("\\$", a)])) 
cat(a, sep="\n") 

$ coefficients 
$ residuals 
$ effects 
$ rank 
$ fitted.values 
$ assign 
$ qr 
..$ qr 
..$ qraux 
..$ pivot 
..$ tol 
..$ rank 
$ df.residual 
$ xlevels 
$ call 
$ terms 
$ model 
..$ prestige 
..$ income 
..$ education 
..$ women 
関連する問題