Skip to content

Commit

Permalink
Fix: #41 Include the correspond from previous year
Browse files Browse the repository at this point in the history
  • Loading branch information
ybkamaleri committed Aug 10, 2021
1 parent 072095b commit 6b00382
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions R/cast-geo.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,18 @@ merge_geo <- function(dt, cor, geo){
# dt - Data from get_code
# cor - Data from get_correspond
# geo - What geo granularity is the data for
DT <- data.table::merge.data.table(dt, cor, by = "code", all = TRUE)
if (geo == "fylke"){
DT <- data.table::merge.data.table(dt, cor, by.x = "kommune", by.y = "code", all = TRUE)
} else {
DT <- data.table::merge.data.table(dt, cor, by = "code", all = TRUE)
}

DT[is.na(name), name := targetName]

grn <- DT[is.na(level), code]
DT[code %in% grn, level := "grunnkrets"]

dtm <- DT[code %in% grn,]
dtm[, `:=`(code = sourceCode, level = geo)]
DT <- data.table::rbindlist(list(DT, dtm))

DT[, name := targetName]
DT[, (geo) := sourceCode]
DT[, c("sourceCode", "sourceName", "targetName") := NULL]
}

0 comments on commit 6b00382

Please sign in to comment.