Learn R Programming

FAOSTAT (version 1.6)

sparsity: A function to calculate the sparsity of the variable

Description

When two or more variables are merged together, it is very likely that spurious sparsity is created. This is due to the fact that the years between the variables are not identicle and is particularly true for data stored as data.frame with country and year as column indexes.

Usage

sparsity(year, var, data)

Arguments

year
The column which index the time
var
The variable to calculate sparsity
data
The data frame.

Details

This function computes the sparsity by taking the data which are observed between the first and the last observation.

For example, if variable A is observed since 1960 while variable B is collected since 1990. When they are merged together, NA's will be created for variable prior to 1990 and these should not be used to calculate the sparsity of the data.