Skip to content

Commit

Permalink
small code fixes to work with latest releases of data.table and resha…
Browse files Browse the repository at this point in the history
…pe packages in R 4
  • Loading branch information
ColSmith76 committed Mar 5, 2021
1 parent 60c5c90 commit 7f0817c
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/scripts/firm_sim_enumerate.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ firm_synthesis_enumerate <- function(cbp, c_n6_n6io_sctg, EmpBounds, cbp_ag = NU
FirmsDomestic[, c("n2","n4") := .(substr(Industry_NAICS6_CBP, 1, 2), substr(Industry_NAICS6_CBP, 1, 4))]

# Melt to create separate rows for each firm size category
FirmsDomestic <- melt(FirmsDomestic,
FirmsDomestic <- melt.data.table(FirmsDomestic,
measure.vars = paste0("e",1:8),
variable.name ="esizecat",
value.name = "est")
Expand Down
2 changes: 1 addition & 1 deletion lib/scripts/firm_sim_input_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ firm_synthesis_input_output <- function(io, c_n6_n6io_sctg){
# Clean and format the input output data
setnames(io, names(io),sub("X", "", names(io)))

io <- melt(io,
io <- melt.data.table(io,
id.vars = "Industry_NAICS6_MakeUse",
variable.name = "Industry_NAICS6_Use",
value.name = "ProVal")
Expand Down
2 changes: 1 addition & 1 deletion lib/scripts/firm_sim_mesozones.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ firm_synthesis_mesozones <- function(Firms){
FirmsCMAP[n2 %in% c("S0"), n2 := "92"]

# Convert the ranking table to long format
mzemp <- melt(mzemp,
mzemp <- melt.data.table(mzemp,
id.vars = c("COUNTY", "MESOZONE"),
variable.name = "n2",
value.name = "EmpRank")
Expand Down
4 changes: 2 additions & 2 deletions lib/scripts/sc_sim_distchannel.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ predict_logit <- function (df, mod, cal = NULL, calcats = NULL, iter = 1) {
sim <- sim/colSums(sim)
if (length(unique(calcats$CHOICE)) < length(unique(calcats$CHID))) {
sim <- cbind(calcats, sim)
sim <- melt(sim, id.vars = c("CHOICE", "CHID"),
sim <- melt.data.table(sim, id.vars = c("CHOICE", "CHID"),
variable.name = "CATEGORY")
sim <- sim[, list(MODEL = sum(value)), by = list(CHOICE,
CATEGORY)]
Expand All @@ -283,7 +283,7 @@ predict_logit <- function (df, mod, cal = NULL, calcats = NULL, iter = 1) {
caldat <- caldat[, list(TARGET = sum(TARGET)),
by = list(CATEGORY, CHID)]
sim <- data.table(CHID = 1:nrow(sim), sim)
sim <- melt(sim, id.vars = c("CHID"), variable.name = "CATEGORY")
sim <- melt.data.table(sim, id.vars = c("CHID"), variable.name = "CATEGORY")
sim <- merge(sim, caldat, c("CATEGORY", "CHID"))
sim[, `:=`(ascadj, log(TARGET/value))]
adj <- sim[, list(CATEGORY, CHID, ascadj)]
Expand Down

0 comments on commit 7f0817c

Please sign in to comment.