Working with dictionaries/lists in R

后端 未结 7 1624
说谎
说谎 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:07

    Yes, the list type is a good approximation. You can use names() on your list to set and retrieve the 'keys':

    > foo <- vector(mode="list", length=3)
    > names(foo) <- c("tic", "tac", "toe")
    > foo[[1]] <- 12; foo[[2]] <- 22; foo[[3]] <- 33
    > foo
    $tic
    [1] 12
    
    $tac
    [1] 22
    
    $toe
    [1] 33
    
    > names(foo)
    [1] "tic" "tac" "toe"
    > 
    
    0 讨论(0)
提交回复
热议问题