Change selected elements of character vector

前端 未结 4 1818
时光取名叫无心
时光取名叫无心 2021-01-24 17:04

Is there a shorter version for the folowing principle to rename certain columns of a data frame?

data1<-data.frame(\"a\"=1:3,\"b\"=1:3,\"c\"=1:3)

data1Names&         


        
4条回答
  •  感动是毒
    2021-01-24 17:52

    You can use rename from the plyr package:

    data1<-data.frame("a"=1:3,"b"=1:3,"c"=1:3)
    > rename(data1,c('a' = 'hello','b' = 'world'))
      hello world c
    1     1     1 1
    2     2     2 2
    3     3     3 3
    

提交回复
热议问题