Add a prefix to column names

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

Leave a Comment