Maybe I'm misunderstanding, but for this to work don't you need a starting data frame that's already been manipulated to make room for all the dates? I thought the OP's question was more about how to make the new rows, not how to make a sequence of dates.
For instance, if I try to adapt this solution to @mishabalyasin's sample data frame above:
library(tidyverse)
df <- tibble::tribble(
~gpi_year, ~gpi_country, ~gpi_score,
"2018", "Iceland", 1.096,
"2018", "South Sudan", 3.508,
"2017", "Iceland", 2,
"2017", "South Sudan", 1
)
date <- c(
rep(as.Date(
as.Date("2018-01-01"):as.Date("2018-12-31"),
origin = '1970-01-01'), 2),
rep(as.Date(
as.Date("2017-01-01"):as.Date("2017-12-31"),
origin = '1970-01-01'), 2)
)
date <- paste(substr(date, 9, 10), substr(date, 6, 7), substr(date, 1, 4), sep = '-')
df<- mutate(df, date = date)
#> Error in mutate_impl(.data, dots): Column `date` must be length 4 (the number of rows) or one, not 1460
Created on 2018-11-08 by the reprex package (v0.2.1)
I'm also not sure I see the virtue of converting an actual date vector into a character vector just to match the OP's preferred date format. For downstream analysis and plotting, I think dates should almost always be dates — the formatting can be handled when it's time for a final presentation.
That said, if I were going to convert the dates to strings, I think I'd use format(date, "%d-%m-%Y") rather than paste(). format() has the distinct benefit of making it obvious at a glance which format was applied, which seems to me like a major win for maintainability.