Re: [R] avoiding a loop?

From: Vincent Goulet <vincent.goulet_at_act.ulaval.ca>
Date: Thu 12 Oct 2006 - 17:02:35 GMT

Le Jeudi 12 Octobre 2006 12:43, Charles Annis, P.E. a écrit :
> I have a vector, (not a list)
>
> > repeated.measures.FACTOR.names
>
> [1] "Insp1" "Insp2" "Insp3" "Insp4" "Insp5" "Insp6" "Insp7" "Insp8" "Insp9"
>
> and would like to convert this into a single string
> "Insp1,Insp2,Insp3,Insp4,Insp5,Insp6,Insp7,Insp8,Insp9"
>
> I can do that with a loop, but isn't there a more elegant way?
>
> > result <- repeated.measures.FACTOR.names[[1]]
> > for(i in 2:length(repeated.measures.FACTOR.names)) {
>
> result <- paste(result, repeated.measures.FACTOR.names[[i]], sep=",") }
>
> > result
>
> [1] "Insp1,Insp2,Insp3,Insp4,Insp5,Insp6,Insp7,Insp8,Insp9"
>
>
> Thanks.
>
> Charles Annis, P.E.
>
> Charles.Annis@StatisticalEngineering.com
> phone: 561-352-9699
> eFax:  614-455-3265
> http://www.StatisticalEngineering.com

paste() will do what you want.

-- 
  Vincent Goulet, Professeur agrégé
  École d'actuariat
  Université Laval, Québec 
  Vincent.Goulet_at_act.ulaval.ca   http://vgoulet.act.ulaval.ca

______________________________________________
R-help@stat.math.ethz.ch 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 Fri Oct 13 03:14:59 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 12 Oct 2006 - 17:30:09 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.