Adding prefix or suffix to most data.frame variable names in piped R workflow

前端 未结 6 1718
一个人的身影
一个人的身影 2020-12-03 05:07

I want to add a suffix or prefix to most variable names in a data.frame, typically after they\'ve all been transformed in some way and before performing a join. I don\'t ha

6条回答
  •  南方客
    南方客 (楼主)
    2020-12-03 06:04

    This is a bit quicker, but not totally what you want:

    dat14 %>%
      group_by(class) %>%
      select(-ID) %>%
      summarise_each(funs(mean(.))) -> means14 
    
    names(means14)[-1] %<>% paste0("_mean_2014")
    

    if you haven't used the %<>%-operator before definitely check this link out, its a super-useful tool.

    you can also use it for recomputing or rounding some columns, like this df$meancolumn %<>% round() , and so on, it just comes up very often and just saves you a lot of writing

提交回复
热议问题