Make sequential numeric column names prefixed with a letter

后端 未结 3 1887
忘掉有多难
忘掉有多难 2020-12-03 15:57

I want to add a label to my dataset. However, the problems is that there are so many columns in my data sets so adding the labels manually is laborious.

I have 33 co

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 16:38

    Here's how I usually do it. sprintf prints the numbers directly. By adding %02d or %03d you can add leading zeroes, which is helpful when dealing with large numbers :D

    features <- c(sprintf("f%02d", seq(1,32)),"label")
    colnames(urc_training_norm) <- features
    

提交回复
热议问题