How to rename element's list indexed by a loop in R

前端 未结 3 1996
你的背包
你的背包 2020-12-10 11:35

I\'m new on R language and I still have a lot to learn. I\'ve a list W of J elements and I would like to rename its elements W[[i]] with Wi

3条回答
  •  被撕碎了的回忆
    2020-12-10 11:52

    A purrr solution using @Quentin's data:

    library(purrr)
    w <- list(a = "give", b = "me an", c = "example") %>% 
      set_names(~paste0("W", 1:length(w)))
    w
    # $W1
    # [1] "give"
    
    # $W2
    # [1] "me an"
    
    # $W3
    # [1] "example"
    

提交回复
热议问题