Learn R Programming

Dict (version 0.10.0)

dict: Create a dictionary

Description

Returns a dictionary in which numbers and string (including vectors of each) can be used as keys, and any R object can be used as value.

Usage

dict(init_keys = NULL, init_values = NULL)

Arguments

init_keys
Optional list of keys for initialization
init_values
Optional list of values for initialization

Value

A dictionary object that can be used to assign and extra values using either the [[ ]] operator or member functions accessed via $.

See Also

numvecdict

Examples

Run this code
# create new dictionary
d <- dict()

# assign an item whose key is c(2:3)
d[[ c(2,3) ]] <- "Test"

# retrieve the element
d[[ c(2,3) ]]

# get will return NULL if the key is not in the dictionary
# (but you can also set the second argument to specify the default value)
d$get("?")

Run the code above in your browser using DataLab