dput失败并给出'结构错误(列表...'在R中

时间:2016-02-12 07:24:38

标签: r

这真的很奇怪,但由于某些原因,我无法将dput与我的数据帧一起使用。

当我运行时:

df_reconstituted <- structure(list(region = c("alabama", "alaska", "arizona", "arkansas", 
"california", "colorado", "connecticut", "delaware", "district of columbia", 
"florida", "georgia", "hawaii", "idaho", "illinois", "indiana", 
"iowa", "kansas", "kentucky", "louisiana", "maine", "maryland", 
"massachusetts", "michigan", "minnesota", "mississippi", "missouri", 
"montana", "nebraska", "nevada", "new hampshire", "new jersey", 
"new mexico", "new york", "north carolina", "north dakota", "ohio", 
"oklahoma", "oregon", "pennsylvania", "rhode island", "south carolina", 
"south dakota", "tennessee", "texas", "utah", "virginia", "washington", 
"west virginia", "wisconsin", "wyoming"), decade = c(1980, 1980, 
1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 
1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 
1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 
1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 1980, 
1980, 1980, 1980, 1980), value = c(628L, 92L, 1636L, 232L, 12690L, 
580L, 1070L, 28L, 460L, 6997L, 210L, 884L, 70L, 3276L, 1775L, 
186L, 250L, 1376L, 2273L, 350L, 921L, 1152L, 3848L, 704L, 502L, 
698L, 146L, 404L, 6678L, 94L, 11270L, 148L, 5957L, 484L, 158L, 
2474L, 1827L, 858L, 3942L, 284L, 1136L, 142L, 1817L, 6887L, 88L, 
1306L, 578L, 648L, 404L, 20L)), class = c("grouped_df", "tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -50L), .Names = c("region", 
"decade", "value"), vars = list(region))

我明白了:

`Error in structure(list(region = c("alabama", "alaska", "arizona", "arkansas",  : 
  object 'region' not found`

我无法想象为什么。看起来包含列“区域”。我唯一想到的可能是原始df的问题。我在它上面使用了很多dplyr,所以它可能是dput无法处理的某种格式。它看起来像这样:

> str(df)
Classes ‘grouped_df’, ‘tbl_df’, ‘tbl’ and 'data.frame':  50 obs. of  3 variables:
 $ region: chr  "alabama" "alaska" "arizona" "arkansas" ...
 $ decade: num  1980 1980 1980 1980 1980 1980 1980 1980 1980 1980 ...
 $ value : int  628 92 1636 232 12690 580 1070 28 460 6997 ...
 - attr(*, "vars")=List of 1
  ..$ : symbol region  

感谢您的任何建议。

0 个答案:

没有答案