Description Usage Arguments Examples
Extract or Replace Parts of a dict
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
x |
Object of class |
i, j |
Indices specifying elements to replace. |
value |
Values to insert into |
name |
Character string or a name. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | # Extracting keys
d <- dict(x = 1, y = 2)
d["x"]
d["z"] <- 3
# Vectorized assignments
new_keys <- c("one", "two")
new_vals <- c(1, 2)
d[new_keys] <- new_vals
d[[letters]] <- LETTERS
d[["a"]]
d[["B"]]
# Vectorized extractions
keys_to_extract <- c("x", "two")
d[keys_to_extract] # return named list
d[[keys_to_extract]] # returns nameless list
## Not run:
d <- dict()
d$x <- 1 # will throw an error
d$x # NULL
d[1] <- 1 # not allowed - key has to be a character
d["a"] <- c(1, 2) # will assign c(1, 2) to name 'a'
d[c("a", "b")] <- c(1, 2) # will assign 1 to 'a' and 2 to 'b'
d[c("a", "b", "c")] <- c(1, 2) # will throw an error
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.