I have a dataframe which consists of 2342 observations with 11 variables. The observation (column DATE) starts from January 01, 2016 and goes till May 31, 2022.
Now I want to add more than 1000 rows so that I can add dates till 2025 to the DATE column. I used the code:
delhi_ra[nrow(delhi_ra) + 1000,]
But this just adds 1 row to the dataframe and it returns an error:
can't assign to columns beyond the end with non-consecutive locations. Input has size Subscript __ contains non-consecutive location.
So the question is how to add more than 1000 rows with dates to the existing dataframe?
(Below is the full code which I have written so far, as a reference).
df_delhi <- rcrea::measurements(country = 'IN', poll = rcrea::PM25, date_from = '2016-01-01', date_to = '2022-05-30', city = 'Delhi')
delhi_ra <- rcrea::utils.running_average(df_delhi,365)
delhi_ra$date <- as.Date(delhi_ra$date)
avg_2017 <- delhi_ra$value[733]
percent_decrease <- 30
NCAP_target <- avg_2017*(100-percent_decrease)/100
delhi_ra$avg_2017 <- NA
delhi_ra$avg_2017[733:2342] <- 78.49
delhi_ra[nrow(delhi_ra)+946,]
#plot the data
colors <- c("PM2.5 level" = "black", "NCAP Target by 2024" = "red")
ggplot(data = delhi_ra, aes(x=date))+
geom_line(aes(y=value, color = 'PM2.5 level'))+
geom_line(aes(y=avg_2017, color = 'NCAP Target by 2024'), linetype = 'twodash')+rcrea::theme_crea()+
labs(title = 'PM2.5 pollution levels in Delhi', x='Year', y='PM2.5', color = 'Legend')+
scale_color_manual(values = colors)+
scale_x_date(limits = as.Date(c('2017-01-01','2025-01-01')), breaks = '1 year', date_labels = "%b %Y")+
scale_y_continuous(expand = c(0, 0), limits = c(0, NA), breaks = breaks_extended(5))