atc-utils: Utilities to work with ATC codes

atcLevelR Documentation

Utilities to work with ATC codes

Description

atcLevel determines the ATC level for the provided ATC code. Note that the level is purely determined by the number of characters. The function does not evaluate whether the provided key represents a valid ATC key/code. See AtcDb for an overview of the various levels.

toAtcLevel transforms the provided ATC code(s) to a lower level code. The function returns 'NA' for codes that have a lower level than the level specified with parameter level.

Usage

atcLevel(x)

toAtcLevel(x, level = 1)

Arguments

x

For atcLevel and toAtcLevel: character representing ATC code(s).

level

integer with the level to which the ATC code(s) should be transformed. Can also have length(level) > 1 in which case each ATC code is converted into an ATC code for each level.

Value

For atcLevel: an integer of length 1 representing the ATC level. The function returns NA if the length of the ATC code does not match any of the levels (i.e. the length of the code is not equal to 1, 3, 4, 5 or 7).

toAtcLevel: if length(level) == 1: returns a character of the same length then x. If length(level) > 1: returns a matrix of ATC codes, each column corresponding to elements in x, each row to ATC levels.

Author(s)

Johannes Rainer

See Also

AtcDb for a listing and description of ATC levels.

Examples


## Get the level for given ATC codes
atcLevel(c("C07AB07", "A12AX"))

## Invalid ATC code
atcLevel("AA")

## Transform an ATC code to a lower level.
toAtcLevel("A01", level = 1)

## Transform one ATC code into two different levels
toAtcLevel("A01CD04", level = c(1, 3))

## Transform two codes.
toAtcLevel(c("A01CD", "A01CD04"), level = 1)

## Transform two codes in 3 levels
toAtcLevel(c("A01CD", "A01CD04"), level = c(1, 3, 2))

jotsetung/atc documentation built on July 29, 2022, 6:57 p.m.