Reputation: 3207
In R, how can I do this
mdf1 <- data.frame(a=c(1:5),b=c(11:15),c=c(21:25),d=c(101:105))
names(mdf1)[2] <- 'A-11:01'
in one operation? Something like:
mdf1 <- data.frame(a=c(1:5),'A-11:01'=c(11:15),c=c(21:25),d=c(101:105))
which produces A.11.01 instead... Thanks!
Upvotes: 1
Views: 731
Reputation: 99331
Use check.names = FALSE
in data.frame()
.
data.frame(a = 1:5, "A-11:01" = 11:15, c = 21:25, check.names = FALSE)
# a A-11:01 c
# 1 1 11 21
# 2 2 12 22
# 3 3 13 23
# 4 4 14 24
# 5 5 15 25
Note: You don't need all those c()
calls around the sequence generation operator :
Upvotes: 3