My Excel file looks like the following
> df
# A tibble: 2 x 3
year item q3
<chr> <chr> <chr>
1 2021 A 7576
2 2021 B 2432
How can I update the Excel file with df
data? That is, how can I fill q3
( row 11, column E) in the Excel file with q3
of df
?
library(dplyr)
library(readxl)
library(writexl)
# Toy Excel data----
df0 <- structure(list(year = c("2019", "2019", NA, NA, "year", "2020",
"2020", NA, NA, "year", "2021", "2021"),
item = c("A", "B", NA, NA, "item", "A", "B", NA, NA, "item", "A", "B"),
q1 = c("2321", "4654", NA, NA, "q1", "2321", "3654", NA, NA, "q1", "7978", "6787"),
q2 = c("3543", "4654", NA, NA, "q2", "3543", "7987", NA, NA, "q2", "4654", "6870"),
q3 = c("7576", "2432", NA, NA, "q3", "7576", "2432", NA, NA, "q3", NA, NA),
q4 = c("13213", "34543", NA, NA, "q4", "13213", "34543", NA, NA, "q4", NA, NA)),
row.names = c(NA, -12L), class = c("tbl_df", "tbl", "data.frame"))
# create Excel file to be used
writexl::write_xlsx(list(example1 = df0), "myfile.xlsx")
# Data to be exported----
df <- tibble(year = c("2021", "2021"),
item = c("A", "B"),
q3 = c("7576", "2432"))