I am brand new to R and have been learning a lot from looking through other questions here on this fine website!
but now I am dealing with a data management issue that I can't figure out from other examples, so I'm hoping that you can help.
I have a set of survey responses that I've read in from a csv file and wrangled into a vector formatted as in the following example:
test <- c(
"[1234],Bob Smith,",
"Q-0,Male",
"Q-1,18-25",
"Q-2,Computer Science",
",",
"[5678],Julie Lewis",
"Q-0,Female",
"Q-1,18-25",
",",
","
)
Note that ","
appears on its own line because I used fill=TRUE
in read.csv
to deal with the fact that not all of the lines were the same length. Also note that not all questions have been answered by all respondents.
I need to turn this into a data frame of the following structure:
ID name gender age major
1 [1234] Bob Smith Male 18-25 Computer Science
2 [5678] Julie Lewis Female 18-25 NA
...
It seems that I can't read the vector into a matrix or data frame by rows because of the fact that not all questions have been answered by all respondents. Any advice on how to deal with this?