Is it possible to index a list R using a character variable and the $ operator?

Can someone explain why I am getting NULL in the following?

 > a = list( 'key'='val') > a$'key' [1] "val" > a$key [1] "val" > key_var = 'key' > a$key_var NULL 

I know what I can do

 > a[[key_val]] [1] "val" 

but I think double brackets can become messy (especially when working with nested lists, etc.).

+1
source share

Source: https://habr.com/ru/post/1258528/


All Articles