Reputation: 2182
I have the following piece of code:
#example
test <- list("a" = 1, "b" = 2)
test2 <- list("x.y.z" = test)
unlist(test2["x.y.z"])
This resulting named vector is the following:
x.y.z.a x.y.z.b
1 2
However, I would like the result to not include the prefix of the nested list. It should be a named vector, but I don't want to include the information of how it was nested. The result I'm looking for:
a b
1 2
I understand that I can probably loop through each item and replace everything except the last character, but I think there should be a more efficient way. Thanks in advance.
Upvotes: 1
Views: 195
Reputation: 388982
Use [[
unlist(test2[["x.y.z"]])
#a b
#1 2
Or $
unlist(test2$x.y.z)
Upvotes: 1