Saturday, 17 August 2013

Repeat colnames in R

Repeat colnames in R

I'm trying to figure out how to repeat a set of column names. Sometimes
I'll have 1 set of columns to name and some other times I'll have 4 sets
of columns to names. For example:
1 set of column names:
r a
2 set of column names:
r a r a
I've tried using this for loop:
for(cnt in 1 numSetCol){
colnames(data[,cnt]) <- "r"
colnames(data[,cnt+1]) <- "a"
cnt <- cnt + 2
}
I get the error: attempt to set colnames on object with less than two
dimensions.
Any help on how to do this would be great.
Thanks!

No comments:

Post a Comment