[R] Simple question

Rolf Turner rolf.turner at xtra.co.nz
Tue Apr 19 23:08:29 CEST 2011


On 20/04/11 07:19, Steven Wolf wrote:
> I am trying to convert a string to a vector, and I'm stuck!
>
>
>
> Suppose you have a string of numbers (string) that you want to convert to a
> vector (vec).  I am able to split the string turning it into a list by using
> strsplit, but this makes a list, which I can't seem to access the way that
> I'd like to (it becomes a character list of only one(?!?) element.)
>
>
>
> string<-"1,1,2,3,5,8"
>
>
>
> list<-strsplit(string,",")
>
> list # Produces this ugly output with the [[1]] crap which doesn't let me
> in!!!!!!!
>
>
>
> vec<-c(1,1,2,3,5,8)  # All I really want in the end.

<SNIP>

It sounds to me like you don't understand lists.  If you are going to use
R you really should understand them.  They are a wonderfully useful
concept and make doing many otherwise complex tasks an absolute
breeze.  Learn to love lists.  It will be rewarding! :-)

     cheers,

         Rolf Turner



More information about the R-help mailing list