How to set the row names of a data frame passed on with the pipe %>% operator?

前端 未结 3 1046
借酒劲吻你
借酒劲吻你 2020-12-29 05:42

I have a data frame which I am dcasting using the reshape2 package, and I would like to remove the first column and have it become the row names of

相关标签:
3条回答
  • 2020-12-29 05:56

    with the later version of tibble, a more elegant solution exists:

    df <- df %>% pivot(.) %>% tibble::column_to_rownames('ID_full')
    

    Importantly, it works also when the column to turn to the rowname is passed as a variable, which is super-convenient, when inside the function!

    0 讨论(0)
  • 2020-12-29 05:58

    will this do?

    iris %>% `rownames<-`(seq_len(nrow(iris)))
    
    0 讨论(0)
  • 2020-12-29 06:16

    You can use the magrittr alias set_rownames:

    df %>% set_rownames(.$ID_full)
    
    0 讨论(0)
提交回复
热议问题