9

dataパッケージ名を指定し、関数が静的出力を生成する関数からの出力をキャプチャしたいと考えています。これをデータフレームに変換したい。

現在、以下は静的出力を提供します。

data(package = "ggplot2")

私はそれをデータフレームにしたいと思っていますが、実際には外部の静的出力を生成することはありません。

diamonds                Prices of 50,000 round cut diamonds
economics               US economic time series.
midwest                 Midwest demographics.
movies                  Movie information and user ratings from IMDB.com.
mpg                     Fuel economy data from 1999 and 2008 for 38 popular models of car
msleep                  An updated and expanded version of the mammals sleep dataset.
presidential            Terms of 10 presidents from Eisenhower to Bush W.
seals                   Vector field of seal movements.
4

1 に答える 1

13

始めるにはこれで十分ですか?

> data(package = "ggplot2")$results
     Package   LibPath                  Item          
[1,] "ggplot2" "/home/mrdwab/R/library" "diamonds"    
[2,] "ggplot2" "/home/mrdwab/R/library" "economics"   
[3,] "ggplot2" "/home/mrdwab/R/library" "midwest"     
[4,] "ggplot2" "/home/mrdwab/R/library" "movies"      
[5,] "ggplot2" "/home/mrdwab/R/library" "mpg"         
[6,] "ggplot2" "/home/mrdwab/R/library" "msleep"      
[7,] "ggplot2" "/home/mrdwab/R/library" "presidential"
[8,] "ggplot2" "/home/mrdwab/R/library" "seals"       
     Title                                                              
[1,] "Prices of 50,000 round cut diamonds"                              
[2,] "US economic time series."                                         
[3,] "Midwest demographics."                                            
[4,] "Movie information and user ratings from IMDB.com."                
[5,] "Fuel economy data from 1999 and 2008 for 38 popular models of car"
[6,] "An updated and expanded version of the mammals sleep dataset."    
[7,] "Terms of 10 presidents from Eisenhower to Bush W."                
[8,] "Vector field of seal movements."    

明らかに、data.frame「アイテム」と「タイトル」のデータのみを取得するには、次を使用できます。

> data.frame(data(package = "ggplot2")$results)[-c(1, 2)]
          Item                                                             Title
1     diamonds                               Prices of 50,000 round cut diamonds
2    economics                                          US economic time series.
3      midwest                                             Midwest demographics.
4       movies                 Movie information and user ratings from IMDB.com.
5          mpg Fuel economy data from 1999 and 2008 for 38 popular models of car
6       msleep     An updated and expanded version of the mammals sleep dataset.
7 presidential                 Terms of 10 presidents from Eisenhower to Bush W.
8        seals                                   Vector field of seal movements.
于 2013-03-03T06:49:10.403 に答える