Reputation: 5098
I have a simple CSV file:
Alpha Beta Gamma
1 4 4
2 6 3
How can I add a specific integer or string to the column names, say 1 or "June"? The output I would expect is:
Alpha_1 Beta_1 Gamma_1
1 4 4
2 6 3
Upvotes: 0
Views: 2160
Reputation: 61214
DF <- read.table(text='
Alpha Beta Gamma
1 4 4
2 6 3', header=TRUE)
colnames(DF) <- paste(colnames(DF), 1, sep='_')
Upvotes: 1
Reputation: 193687
Use paste
or paste0
with names
.
Assuming your data.frame
is called test
: names(test) = paste0(names(test), "_1")
Upvotes: 2