Slight addendum. Working from your code, I found 1 line of code does the
conversion:
myColumn = unlist(strsplit(as.character(myData[[myQuestion]]),","));
But the dataframe you set up may prove more useful.
Regards,
Damion
-----Original Message-----
From: Magnus Torfason [mailto:[email protected]]
Sent: August 19, 2009 12:33 PM
To: Damion Dooley
Cc: [email protected]
Subject: Re: [R] Basic question: Reading in multiple choice question
responses to a single column in data frame
Are you looking for something like this?
> d = data.frame(a=1:5,b=c("1","2,3","2","3,4","1"))
> d
a b
1 1 1
2 2 2,3
3 3 2
4 4 3,4
5 5 1
> multis = strsplit(d$b,",")
> counts = sapply(strsplit(d$b,","),length )
> d2 = data.frame( a=rep(d$a,counts), b=unlist(multis) )
> d2
a b
1 1 1
2 2 2
3 2 3
4 3 2
5 4 3
6 4 4
7 5 1
Best,
Magnus
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.