[R] Loop over a split string

Paul Hiemstra paul.hiemstra at knmi.nl
Wed May 11 11:30:24 CEST 2011


 Hi Joel,

This looks so much like homework I would give studens that I'm not
surprised Uwe jumped to conclusions...

ontopic:
You did not specify your earlier attempts, just that they failed. This
makes it hard for us to judge what went wrong. Using strsplit I would do:

string<-"a b c d e f"
# The important bit is the subset ([[1]])
# strsplit can work on a vector of strings
# so just splitting on string requires this step
splitted <- strsplit(string, ' ')[[1]]
for(entry in splitted) print(entry)

cheers,
Paul

On 05/11/2011 09:22 AM, Joel wrote:
> This is no homework, Im just trying to learn R but sorry for wasting your
> time you all mighty God of R Uwe Ligges.
>
> And if this is not a forum to ask simple questions can you please redirect
> me to where I might get help? 
>
> //Joel
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Loop-over-a-split-string-tp3514204p3514225.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.


-- 
Paul Hiemstra, MSc
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770



More information about the R-help mailing list