0

What I am trying to do is hopefully very simple. I have a vector of names that are to become the variable names in a data frame. The end result is a data frame with (initially) no data, but with 210 named variables as per the vector called "label". Any ideas as to how to do this?

vector0 <- c("a", "b", "c", "d", "e", "f", "g")
vector1 <- rep(1:3, times=1, each=70)
vector2 <- rep(1:5, times=1, each=14)
vector3 <- rep(1:2, times=1, each=7)
label <- paste(vector0, vector1, vector2, vector3, sep="")
aspark2020
  • 331
  • 1
  • 12

1 Answers1

1

You say "no data", so I suppose you want a data frame without any data, not even NA's:

df <- as.data.frame(replicate(210, numeric()))

Now you're ready to change the names:

names(df) <- label # `label` from OP

Or in one shot:

df <- setNames(as.data.frame(replicate(210, numeric())), label)
lebatsnok
  • 5,928
  • 2
  • 20
  • 22