Learn R Programming

FAOSTAT (version 1.6)

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

Value

  • A data frame with the new constructed variable

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).

Examples

Run this code
## 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")

Run the code above in your browser using DataLab