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

前端 未结 3 1993
你的背包
你的背包 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:44

    names(W) <- paste0("W", seq_along(W))
    

    should do the trick.

    Note that paste0 was introduced in R 2.15 as a "slightly more efficient" version of paste(..., sep = "", collapse) . If you are using an earlier version of R, you can achieve the same using paste:

    names(W) <- paste("W", seq_along(W), sep = "")
    

提交回复
热议问题