[R] Use quotes on a FOR LOOP R

R. Michael Weylandt michael.weylandt at gmail.com
Tue Apr 24 21:22:54 CEST 2012


Don't you just want

LIST <- as.data.frame(LIST, stringsAsFactors = FALSE) # Avoid making factors

for(n in LIST) print(n)

But I can't understand why you want to do it this way.... I'll presume
this makes more sense in your application.

On Tue, Apr 24, 2012 at 2:29 PM, michaelyb <cel81009759 at gmail.com> wrote:
> Hello All!
>
> I need some help to get a FOR LOOP to print the interactor with the
> quotation mark.
>
> Let me be more specific:
>
> I have the following:
> cbind("Michael","Dana","Rob")->LIST
>
> outcome:
>     [,1]      [,2]   [,3]
> [1,] "Michael" "Dana" "Rob"
>
> UNFORTUNATELY, I need to do the following:
> as.data.frame.list(LIST)->LIST2
> rm(LIST)
>
> outcome:
>  X.Michael. X.Dana. X.Rob.
> 1    Michael    Dana    Rob
>
> My problem:
> I tried the following LOOP:
> for (n in LIST2)print((paste("\'",n,"\'"))
>
> outcome:
> [1] "*'* Michael *'*"
> [1] "*'* Dana*'*"
> [1] "*'* Rob*'*"
>
> How can I get the following instead:
> [1] "Michael"
> [1] "Dana"
> [1] "Rob"
>
> Detail: I cannot use the first LIST to do the FOR LOOP since I need to
> remove it first.
> Any help, please?
>
> Thank you!
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Use-quotes-on-a-FOR-LOOP-R-tp4584438p4584438.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.



More information about the R-help mailing list