Applying dplyr's rename to all columns while using pipe operator

前端 未结 5 1321

I\'m working with an imported data set that corresponds to the extract below:

set.seed(1)
dta <- data.frame(\"This is Column One\" = runif(n = 10),
               


        
5条回答
  •  旧巷少年郎
    2021-01-04 03:51

    Set column names with the pipe like so:

    iris %>% `colnames<-`(c("newcol1", "newcol2", "newcol3", "newcol4", "newcol5"))
    

    Which returns

        newcol1 newcol2 newcol3 newcol4    newcol5
    1       5.1     3.5     1.4     0.2     setosa
    2       4.9     3.0     1.4     0.2     setosa
    3       4.7     3.2     1.3     0.2     setosa
    

提交回复
热议问题