I'm trying to create a long tibble dataframe with a date sequence. Now I tried to use this example. The example works but not when I try to implement to my own data. It gives an error message: Error in seq.int(0, to0 - from, by) : wrong sign in 'by' argument. At can't figure out why the code on my tibble throws an error... All help much appreciated.
This example works:
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)
That's kind of what I'm looking for.
The code on my data gives an error message.
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
The error message say it has to do with the by = argument but I can't understand why it's not working...