【发布时间】:2019-08-08 23:25:58
【问题描述】:
我正在尝试创建一个带有日期序列的长 tibble 数据框。现在我尝试使用这个example。该示例有效,但当我尝试实现自己的数据时无效。它给出了一条错误消息:Error in seq.int(0, to0 - from, by) : wrong sign in 'by' argument。无法弄清楚为什么我的 tibble 上的代码会引发错误......非常感谢所有帮助。
这个例子有效:
library(tidyverse)
example <- structure(list(idnum = c(17L, 17L, 17L), start = structure(c(8401,
8401, 8401), class = "Date"), end = structure(c(8765, 8765, 8765
), class = "Date")), class = "data.frame", .Names = c("idnum",
"start", "end"), row.names = c(NA, -3L))
example %>%
as.tibble() %>%
nest(start, end) %>% view
mutate(data = map(data, ~seq(unique(.x$start), unique(.x$end), 1))) %>%
unnest(data)
这正是我想要的。
我的数据上的代码给出了一条错误消息。
df <- structure(list(nieuw = c("Nieuw", "Nieuw", "Nieuw"), jaar = c(NA,
2013, 2014), aow_jaar = c("65", "65", "65"), aow_maanden = c(NA,
"1", "2"), vanaf = structure(c(-8036, -8036, -7701), class = "Date"),
tot_en_met = structure(c(-8037, -7702, -7367), class = "Date")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -3L))
df %>%
nest(vanaf, tot_en_met) %>%
mutate(data = map(data, ~seq(unique(.x$vanaf), unique(.x$tot_en_met), 1))) %>%
unnest(data)
Error in seq.int(0, to0 - from, by) : wrong sign in 'by' argument
错误消息说它与 by = 参数有关,但我不明白为什么它不起作用...
【问题讨论】:
-
问题是第一行
1948-01-01 1947-12-31。第二次约会较少