Learn R Programming

hicp (version 1.1.0)

coicop.relatives: COICOP relatives

Description

The functions parent() and child() derive the higher-level parents or lower-level children of a COICOP code.

Usage

child(id, usedict=TRUE, closest=TRUE, k=1, settings=list())

parent(id, usedict=TRUE, closest=TRUE, k=1, settings=list())

Value

A list with the same length as id.

Author

Sebastian Weinand

Arguments

id

character vector of COICOP codes.

usedict

logical indicating if parents or children should be derived from the full code dictionary defined by settings$coicop.version (if set to TRUE) or only from the codes present in id.

closest

logical indicating if the closest parents or children should be derived or the k-th ones defined by k. For example, if set to TRUE, the closest parent could be the direct parent for one code (e.g. 031->03) and the grandparent for another (e.g. 0321->03).

k

integer specifying the k-th relative (e.g., 1 for direct parents or children, 2 for grandparents and grandchildren, ...). Multiple values allowed, e.g., k=c(1,2). Only relevant if closest=FALSE.

settings

list of control settings to be used. The following settings are supported:

  • coicop.version : character specifying the COICOP version to be used. See coicop for the allowed values. The default is getOption("hicp.coicop.version").

  • coicop.prefix : character specifying a prefix for the COICOP codes. The default is getOption("hicp.coicop.prefix").

  • all.items.code : character specifying the code internally used for the all-items index. The default is taken from getOption("hicp.all.items.code").

  • simplify : logical indicating if the output should be simplified into a vector if possible. The default is FALSE. If both a COICOP bundle code and the underlying codes are the parent or child, only the latter codes are kept (e.g., c(08X,082)->082). Note that simplification usually only works for parent().

See Also

coicop, tree

Examples

Run this code
# no children of CP01 present in id:
child(id="CP01", usedict=FALSE) 

# still no direct child present:
child(id=c("CP01","CP0111"), usedict=FALSE, closest=FALSE, k=1) 

# but a grandchild of CP01 is found:
child(id=c("CP01","CP0111"), usedict=FALSE, closest=TRUE) 

# now, get the children directly from the code dictionary:
child(id=c("CP01","CP0111"), usedict=TRUE) 

# which works analogously for parents:
parent(id=c("CP01","CP0111"), usedict=TRUE)

Run the code above in your browser using DataLab