1
I am looking for data from IBGE (SIDRA), I need to add the last data and update the 3 previous periods, without changing or messing with the old data.
Follows the code:
library(sidrar)
df <- get_sidra (api = "/t/1846/n1/all/v/all/p/all/c11255/90707/d/v585%200")
#Selecionando as colunas que me interessa
df1 <- df[,c(7,10,13)]
This returns me the historical series of GDP
df1 <- Trimestre (Código) Setores e subsetores Valor
199601 PIB a preço de mercado 189323
... ... ...
201903 PIB a preço de mercado 1842700
201904 PIB a preço de mercado 1842740
And saved this file on my computer
read.xlsx("df1.xlsx", sheetName = "PIB", header = TRUE)
When a new data comes out, 202001, IBGE revises 3 previous data (201902, 201903, 201904) and publishes 202001,
then I just run the code to fetch the last 4 data, to avoid having to fetch the complete series
df2 <- get_sidra (api = "/t/1846/n1/all/v/all/p/last%203/c11255/90707/d/v585%200")
After having my df2, I want to update the data for 201902, 201903 and 201904, and add the data for 202001
To add only the new data, I was using :
wb <- loadWorkbook("df1.xlsx")
addDataFrame(df2,getSheets(wb)$df2, col.names = FALSE, row.names = FALSE, startRow = nrow(read.xlsx("df1.xlsx", sheetName = "PIB"))+2)
saveWorkbook(wb,"df1.xlsx")
But this function doesn’t help me update my previous information. Could someone tell me how I can do this?
Hi, Jorge! Thanks for the help, I also managed to play here!
– Larissa Castro