2013-03-03 28 views
8

Tôi muốn chụp đầu ra từ chức năng data trong đó bạn cung cấp tên gói và chức năng tạo ra đầu ra tĩnh. Tôi muốn biến điều này thành một khung dữ liệu.Đầu ra chụp dữ liệu

Hiện nay những điều sau đây sẽ cho sản lượng tĩnh:

data(package = "ggplot2") 

Tôi muốn nó được như một dataframe và thực sự không bao giờ có kết quả tĩnh bên ngoài sản xuất.

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. 
+1

Something như 'as.data.frame (dữ liệu() [[3 ]] [, 3: 4]) '? –

+0

gần như nhưng điều này sẽ là cho một gói cụ thể. –

+0

Bạn cũng có thể thích trang này liệt kê các tập dữ liệu R từ một loạt các pakcages: http://vincentarelbundock.github.com/Rdatasets/ – daroczig

Trả lời

13

Điều này có đủ để giúp bạn bắt đầu không?

> 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."  

Rõ ràng, để có được một data.frame của chỉ là "Item" và "Tiêu đề" dữ liệu, bạn có thể sử dụng:

> 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. 
+0

Đủ hơn +1 –

+0

Làm thế nào về việc nhận được kết quả của changepoint (cpt.mean) và bản vẽ của nó (giá trị cốt truyện (xyz))? – bjan

+0

@bjan, tôi không chắc chắn cách bình luận của bạn liên quan đến câu hỏi này ... Có phải 'cpt.mean' là một hàm trong một gói cụ thể và bạn đang cố gắng trích xuất các giá trị của nó? Nếu vậy, tôi sẽ bắt đầu ở trang trợ giúp và xem liệu nó có xác định loại giá trị nào được trả về hay không (thường là trong phần có tên là "Giá trị"). – A5C1D2H2I1M1N2O1R2T1

Các vấn đề liên quan