问题描述
我正在尝试重新生成数据框,而 dput
不合作。
I'm trying to reproduce a data frame and dput
is not cooperating.
dput
命令:
dput(head(data, 10))
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 in structure(list(lexptot = c(8.28377505197124, 9.1595012302023, :
object 'nh' not found
为什么这是从dput命令发生的?
Why is this happening right from a dput command?
编辑:
相关帖子,但建议无效。
Relevant posts, but suggestions did not work.
Why does this dplyr dput not work?
编辑2:
出现这是因为我的一个变量是 / code>对象,dput不能重现这个。解决方案是使用
ungroup(data)
然后重新运行dput并且都可以工作。
It appears because one of my variables is a group
object, dput cannot reproduce this. The solution is to use ungroup(data)
then rerun dput and all works.
推荐答案
问题是一个变量对象是组
,因此, dput()
不能认识到这一点解决方案是 ungroup()
数据。
The issue was one of the variable objects was a group
and therefore, dput()
couldn't recognize this. The solution was to ungroup()
the data.
ungroup(data)
dput(head(data, 10))
New Data.frame: p>
New 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))
这篇关于可重复的示例和dput错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!