Working with dictionaries/lists in R

后端 未结 7 1637
说谎
说谎 2020-12-07 09:14

I have trivial question: I couldn\'t find a dictionary data structure in R, so I used list instead (like \"word\"->number) So, right now I have problem how to get the list o

7条回答
  •  孤街浪徒
    2020-12-07 10:04

    Shorter variation of Dirk's answer:

    # Create a Color Palette Dictionary 
    > color <- c('navy.blue', 'gold', 'dark.gray')
    > hex <- c('#336A91', '#F3C117', '#7F7F7F')
    
    > # Create List
    > color_palette <- as.list(hex)
    > # Name List Items
    > names(color_palette) <- color
    > 
    > color_palette
    $navy.blue
    [1] "#336A91"
    
    $gold
    [1] "#F3C117"
    
    $dark.gray
    [1] "#7F7F7F"
    

提交回复
热议问题