Is there any dictionary-like structure in R

Viewed 181

I have a string vector like

sv = c('xx_S1_xx', 'xx_S1_xx', 'xx_S2_xx', 'xx_S3_xx', ...)

But I have difficuly to find a dictionary-like structure so I can convert it to

map = { S1=>c('xx_S1_xx', 'xx_S1_xx'), S2=>c('xx_S2_xx'), S3=>c('xx_S3_xx'), ... }

Any suggestions?

1 Answers

in R a named list is the nearest thing to a dictionary or hashed array or whatever any other language calls it.

Construct with the list function and extract/assign elements with the $ operator:

> SLIST = list(S1=c("x_S1_x","x_S1_x"), S2="xx_S2_xx", S3="xx_S3_xx")
> SLIST$S1
[1] "x_S1_x" "x_S1_x"
Related