2

i have a variable containing character names and i want to make each character into a name within a data frame. is there a quick way to do this that is automated as i have different variables with different amounts of characters i want to turn into data frames?

for example

variables with character names

names <- c("one","two","three")

the output i want

dataframe <- data.frame(one = NA, two = NA, three = NA)
dataframe
  one two three
1  NA  NA    NA

thanks

  • 1
    You can do `data.frame(Map(function(...) NA, names))`, but a better question would be why are you doing this? You're going to to try to add rows one at a time to this data.frame are you? That's very un-R-like. – MrFlick Nov 16 '18 at 21:18
  • thanks for your response - its part of a loop, so yeh, im going to be adding predictions to each row, however, depending on the data input, some of the variable names change and i need the col names to change as well, hence why i wanted to column names to auto update. – ManyQsFewAs Nov 17 '18 at 02:57

0 Answers0