79 min read

Webscraping JSON Data

req <- 'https://data.gov.sg/dataset/7a339d20-3c57-4b11-a695-9348adfd7614/resource/42ff9cfe-abe5-4b54-beda-c88f9bb438ee/data?limit=6000'

df <- fromJSON(req)$records %>% 
  as_tibble() %>% 
  mutate(town = str_to_title(town), 
         flat_type = str_to_title(flat_type),
         floor_area_sqm = as.numeric(floor_area_sqm),
         street_name  = str_to_title(street_name),
         resale_price = as.numeric(resale_price), 
         lease_commence_date = as.numeric(lease_commence_date), 
         storey_range = str_to_lower(storey_range), 
         block = paste0("Blk", block)) %>% 
  separate(month, c("year", "month"), sep = "-") %>% 
  mutate(year = as.numeric(year),
         month = as.numeric(month), 
         desc = paste0(town, "|", block, "|", storey_range, "|", 
                       flat_model, "|", flat_type, "|", floor_area_sqm, ":Mth", month)) %>% 
  select(-12)

Codes and the data table will be available on RPubs soon. You can get the list from there.