我試圖重現數據幀和dput
不合作。可重複的示例和輸入錯誤
dput
命令:
dput(head(data, 10))
dput
輸出:
structure(list(lexptot = c(8.28377505197124, 9.1595,
8.14707583238833, 9.86330744180814, 8.21391453619232, 8.92372556833205,
7.77219149815994, 8.58202430280175, 8.34096828565733, 10.1133857229336
), year = c(0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L), dfmfdyr = c(0,
1, 0, 1, 0, 1, 0, 1, 0, 1), dfmfd98 = c(1, 1, 1, 1, 1, 1, 1,
1, 1, 1), nh = c(11054L, 11054L, 11061L, 11061L, 11081L, 11081L,
11101L, 11101L, 12021L, 12021L)), .Names = c("lexptot", "year",
"dfmfdyr", "dfmfd98", "nh"), vars = list(nh), drop = TRUE, indices = list(
0:1, 2:3, 4:5, 6:7, 8:9), group_sizes = c(2L, 2L, 2L, 2L,
2L), biggest_group_size = 2L, labels = structure(list(nh = c(11054L,
11061L, 11081L, 11101L, 12021L)), class = "data.frame", row.names = c(NA,
-5L), .Names = "nh", vars = list(nh)), row.names = c(NA, 10L), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
錯誤:
Error in structure(list(lexptot = c(8.28377505197124, 9.1595, :
object 'nh' not found
這是爲什麼從dput命令發生吧?
編輯:
相關帖子,但建議沒有奏效。
Why does this dplyr dput not work?
編輯2:
看來,因爲我的變量之一是group
對象,dput無法重現此。解決方法是使用ungroup(data)
然後重新運行dput和所有的作品。
我已經添加了dplyr標籤,因爲這可能是你的問題的根源。由於我不使用dplyr,因此無法進一步幫助您。 – Roland 2015-03-13 18:40:16
@Roland爲什麼這是一個dplyr問題? – Vedda 2015-03-13 18:41:50
如果您擁有「正常」數據框,通常情況下不會出現此問題。但你有一個'grouped_df',這很可能是相關的。我在那裏看到'vars = list(nh)',這是對另一個通常不是'dput'輸出的一部分的對象的引用。 – Roland 2015-03-13 18:44:32