forked from pik-piam/mrtutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalcAgGDP.R
More file actions
32 lines (26 loc) · 750 Bytes
/
Copy pathcalcAgGDP.R
File metadata and controls
32 lines (26 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#' @title calcAgGDP
#' @description calculates Ag GDP as % of total GDP
#'
#' @return List of magpie object with results on country level, weight, unit and description.
#' @author David Chen
#' @examples
#'
#' \dontrun{
#' calcOutput("AgGDP")
#' }
#' @importFrom magclass collapseNames
#' @importFrom madrat readSource
calcAgGDP <- function(){
gdp <- readSource("TutorialWDI", subtype="NY.GDP.MKTP.CD")
ag_gdp <- readSource("TutorialWDI", subtype="NV.AGR.TOTL.CD")
x <- ag_gdp/gdp
x <- collapseNames(x)
getNames(x) <- "Ag_GDP_share"
## some division by 0 happening
x[is.na(x)] <- 0
return(list(
x=x,
weight=NULL,
unit="share",
description="Ag GDP as percentage of total GDP"))
}