Skip to content

Commit

Permalink
use r2dii.data::increasing_or_decreasing
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhoffa committed Jul 19, 2023
1 parent 571a876 commit 8dd4345
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions R/summarize_weighted_production.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ add_percent_change <- function(data) {

check_zero_initial_production(data)

green_or_brown <- r2dii.data::green_or_brown
increasing_or_decreasing <- r2dii.data::increasing_or_decreasing

data %>%
inner_join(green_or_brown, by = c(
inner_join(increasing_or_decreasing, by = c(
sector_abcd = "sector",
technology = "technology"
)) %>%
Expand All @@ -266,15 +266,15 @@ add_percent_change <- function(data) {
group_by(.data$sector_abcd, .data$name_abcd) %>%
arrange(.data$name_abcd, .data$year) %>%
mutate(
brown_percent_change =
decreasing_percent_change =
(.data$production - first(.data$production)) /
first(.data$production) * 100,
green_percent_change = (.data$production - first(.data$production)) /
increasing_percent_change = (.data$production - first(.data$production)) /
first(.data$sector_production) * 100
) %>%
mutate(percent_change = dplyr::case_when(
green_or_brown == "green" ~ green_percent_change,
green_or_brown == "brown" ~ brown_percent_change
increasing_percent_change == "increasing" ~ increasing_percent_change,
increasing_percent_change == "decreasing" ~ decreasing_percent_change
)) %>%
select(one_of(c(names(data), "percent_change"))) %>%
ungroup()
Expand Down

0 comments on commit 8dd4345

Please sign in to comment.