| cpp_map | R Documentation |
Create a map. Maps are key-value pairs sorted by unique keys.
cpp_map(keys, values)
keys |
An integer, numeric, character, or logical vector. |
values |
An integer, numeric, character, or logical vector. |
Maps are associative containers. They do not provide random access through an index. I.e. m[2] does not return the second element.
C++ map methods implemented in this package are at, clear, contains, count, emplace, empty, erase, insert, insert_or_assign, max_size, merge, size, and try_emplace. The package also adds the == and [ operators and various helper functions (print, to_r, type).
All object-creating methods in this package begin with cpp_ to avoid clashes with functions from other packages, such as utils::stack and
base::vector.
Returns a CppMap object referencing a map in C++.
cpp_unordered_map, cpp_multimap, cpp_unordered_multimap.
m <- cpp_map(4:6, seq.int(1, by = 0.5, length.out = 3L))
m
# [4,1] [5,1.5] [6,2]
insert(m, seq.int(100, by = 0.1, length.out = 3L), 14:16)
m
# [4,1] [5,1.5] [6,2] [14,100] [15,100.1] [16,100.2]
print(m, from = 6L)
# [6,2] [14,100] [15,100.1] [16,100.2]
m <- cpp_map(c("world", "hello", "there"), 4:6)
m
# ["hello",5] ["there",6] ["world",4]
erase(m, "there")
m
# ["hello",5] ["world",4]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.