Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

shConstruct

Construct share variable


Description

A function for constructing the share of a variable of an aggregated variable.

Usage

shConstruct(data, totVar, shareVar, newVarName = NA)

Arguments

data

The data frame containing both the share variable and the aggregated variable

totVar

The aggregated variable.

shareVar

The subset of the aggregated variable which to be divided by.

newVarName

The name assigned to the new variable, if missing then .SC/.SH/.GR will be appended depending on the type of construction

Details

The share of a variable can be share of the World (if additional variable were not supplied) or share of another variable (per Capita if population was supplied).

Value

A data frame with the new constructed variable

Examples

## Total variables provided, scale by totVar
test.df = data.frame(FAOST_CODE = 1, Year = 1990:1994, a = 1:5, b = 1:5)
shConstruct(data = test.df, totVar = "a", shareVar = "b")

## Total variables not provided, scale by world aggregate.
test.df2 = data.frame(FAOST_CODE = rep(c(1, 5000), each = 5),
                       Year = rep(1990:1994, 2),
                       a = rep(1:5, 2), b = rep(1:5, 2))
shConstruct(data = test.df2, totVar = NA, shareVar = "b")

FAOSTAT

Download Data from the FAOSTAT Database

v2.2.1
GPL (>= 2)
Authors
Michael C. J. Kao <michael.kao@fao.org>, Markus Gesmann, Filippo Gheri
Initial release
2020-11-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.