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

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

    Alternatively you can use sprintf():

     w<-list(a="give",b="me an",c="example")
     names(w)<-sprintf("W%i",1:length(w))
    

    As you can see, you do not need a loop for this.

    It should do the work. In this example, the names are W1,W2 and W3

    print(w)
    $W1
    [1] "give"
    
    $W2
    [1] "me an"
    
    $W3
    [1] "example"
    

提交回复
热议问题