Re: [R] Simple question

From: Rolf Turner <rolf.turner_at_xtra.co.nz>
Date: Wed, 20 Apr 2011 09:08:29 +1200

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



R-help_at_r-project.org 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. Received on Tue 19 Apr 2011 - 21:12:27 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Apr 2011 - 21:20:31 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive