Skip to content
Prev 75385 / 398502 Next

Converting strings with internal delimiters into lists

???  I guess I don't get it.

Note that
as.data.frame(cbind(c("Joe,Mary,Jane","Mary"),c("Fred,Joe","Pete,Joe,Mary,Fr
ed")))

is probably not what you want since cbind expects vectors of equal length.
By default, shorter vectors are recycled to the length of the longest one,
which I doubt is what you want.

Why isn't
mylist<-list(c("Joe,Mary,Jane","Mary"),c("Fred,Joe","Pete,Joe,Mary,Fred"),..
.)

suitable? S lists are specifically designed to handle different objects with
different lengths (or totally different objects). lapply(), sapply() and
friends or for() loops can then work over such a list to do what you want.

-- Bert Gunter
Genentech Non-Clinical Statistics
South San Francisco, CA
 
"The business of the statistician is to catalyze the scientific learning
process."  - George E. P. Box