简体   繁体   English

可重现的示例和输出错误

[英]Reproducible example and dput error

I'm trying to reproduce a data frame and dput is not cooperating. 我正在尝试重现数据帧,而dput无法合作。

dput command : dput命令:

dput(head(data, 10))

dput output : dput输出:

structure(list(lexptot = c(8.28377505197124, 9.1595012302023, 
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 : 错误:

Error in structure(list(lexptot = c(8.28377505197124, 9.1595012302023,  : 
  object 'nh' not found

Why is this happening right from a dput command? 为什么在dput命令中会发生这种情况?

Edit : 编辑:

Relevant posts, but suggestions did not work. 相关帖子,但建议不起作用。

Why does this dplyr dput not work? 为什么此dplyr dput不起作用?

Edit 2 : 编辑2:

It appears because one of my variables is a group object, dput cannot reproduce this. 由于我的变量之一是group对象,因此dput无法重现该变量。 The solution is to use ungroup(data) then rerun dput and all works. 解决方案是使用ungroup ungroup(data)然后重新运行dput并完成所有工作。

The issue was one of the variable objects was a group and therefore, dput() couldn't recognize this. 问题是变量对象之一是一个group ,因此dput()无法识别。 The solution was to ungroup() the data. 解决的办法是ungroup()数据。

ungroup(data)
dput(head(data, 10))

New Data.frame : 新的Data.frame:

structure(list(lexptot = c(8.28377505197124, 9.1595012302023, 
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), dfmfd98 = c(1, 
1, 1, 1, 1, 1, 1, 1, 1, 1), dfmfd = c(0L, 1L, 0L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L)), .Names = c("lexptot", "year", "dfmfd98", "dfmfd"
), class = c("tbl_df", "data.frame"), row.names = c(NA, -10L))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM