I need to create a data.frame that will be populated one row at a time by results of a for loop. It has 45 columns: the names of five of these are static but the remainder are read in (as a vector) from an external CSV file at run time. I’m looking for something along the lines of
goalsMenu <- read.csv("Phase 1 goalsmenu.csv", header = TRUE)
colHeads <- c("analysis","patient","date",as.vector(goalsMenu$Name),"CR")
output <- data.frame(colHeads)
however this creates a one-column data.frame with column name of colHeads.
colHeads <- list("analysis","patient","date",as.vector(goalsMenu$Name),"CR")
seems a step in the right direction but I need to “flatten” it to create the desired data.frame structure
could you advise please?
Does this help?
Basically, I create a data.frame
outputwith the number of columns first and name those columns in the next step. However, be aware about mdsumner’s comment! This way, all columns are of classnumeric. You can deal with that later though: change the class of columns in data.frame