[R] Loop over a split string

peter dalgaard pdalgd at gmail.com
Wed May 11 12:48:31 CEST 2011


On May 11, 2011, at 11:35 , Joel wrote:

> Thx
> 
> Paul
> 
> My string aint that simple its just that if it works for this simple example
> it will work for my string therefor I just used the "a b c d e f" syntax.


> strsplit(string," ")
[[1]]
[1] "a" "b" "c" "d" "e" "f"

> strsplit(string," ")[[1]]
[1] "a" "b" "c" "d" "e" "f"
> for(i in strsplit(string," ")[[1]]) cat(i, "\n")
a 
b 
c 
d 
e 
f 
> cat(strsplit(string," ")[[1]], sep="\n")
a
b
c
d
e
f
> 


-- 
Peter Dalgaard
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list