Add a prefix to column names

后端 未结 4 807
情深已故
情深已故 2020-11-28 03:52

When reading the following helpfile it should be possible to add a prefix to the column names :

colnames(x, do.NULL = TRUE, prefix = \"col\")
4条回答
  •  春和景丽
    2020-11-28 04:30

    You have misread the help file. Here's the argument to look at:

    do.NULL: logical. If FALSE and names are NULL, names are created.

    Notice the and in that description. Your names are no longer NULL, so using prefix won't work.

    Instead, use something like this:

    > m2 <- cbind(1,1:4)
    > colnames(m2) <- c("x","Y")
    > colnames(m2) <- paste("Sub", colnames(m2), sep = "_")
    > m2
         Sub_x Sub_Y
    [1,]     1     1
    [2,]     1     2
    [3,]     1     3
    [4,]     1     4
    

提交回复
热议问题