Tried googling and youtube but still stuck, so here it goes:
I download a df from an API and since I want my update to always get the latest yr and month I don't want to specify that in my list that I send to the API. This means that I get my results for all yrs and months. -> Since I'm only interested in the latest entry (e.g. latest month) I need some function to identify which is the latest date in the df and then get rid of all data that is older than that.
I've converted the column, called "månad" to Date (format: YYYY-MM-DD), but what's next?
CODE
library(pxweb)
library(tidyverse)
library(lubridate)
# PXWEB query - create list
pxweb_query_list_BAS <-
list("Region"=c("22"),
"Kon" =c("1","2"),
"Alder" =c( "20-24",
"25-29",
"30-34",
"35-39",
"40-44",
"45-49",
"50-54",
"55-59",
"060-64"),
"Fodelseregion" = c("in","ut"),
"ContentsCode"=c("000006IJ"))
#"Tid" = "2022M09")
# Download data using created list
px_data_BAS <-
pxweb_get(url = "https://api.scb.se/OV0104/v1/doris/sv/ssd/START/AM/AM0210/AM0210A/ArbStatusM",
query = pxweb_query_list_BAS)
# Convert list to df
df_arbetskraftd <- as.data.frame(px_data_BAS, column.name.type = "text", variable.value.type = "text")
#Convert class of col. månad from chr (string) to date
df_arbetskraftd$månad <- ym(df_arbetskraftd$månad)
DF - overview
If I can get a value of latest date in that format I guess I can figure out how to create the new df in some way (right now I thinking creating a new df with that date and then merging, maybe not the smartest) - but feel free to suggest solution here too.
Thanks!