I have successfully added a new blank row 1 “24727.2” but I want to duplicate the values from columns 2:11 named 2009:2018 in row [5] “state=24727” to row 1. Then I want to change the values for columns less than 2016 to NA only in row 1. I can’t seem to get the duplicate/replicate data to copy/paste into row 1 “24727.2” using ifelse, mutate_at or mutate_each, replace_na(), or summarise. Any help or assistance is appreciated.
library(dplyr)
library(tidyr)
library(tibble)
temp <- data %>%
group_by(year, state) %>%
summarise(mean.var3 = mean(var3)) %>%
spread(year, mean.var3) %>%
do(add_row(., state=24727.2, .before=1)) %>%
print(temp)