[R] Converting strings with internal delimiters into lists

Berton Gunter gunter.berton at gene.com
Thu Aug 11 19:58:42 CEST 2005


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

Note that

>  testtable<-
>
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




More information about the R-help mailing list