[R] problem with grep under loop

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Sat Sep 14 04:21:00 CEST 2013


This is because you are not printing it (with the print or cat functions). Keep in mind that the visible result you get from calling a function or evaluating a variable interactively comes from the interactive R command line, not from R itself. Once you put such an expression inside a function (such as the "for" function) it is no longer directly being invoked by the command interpreter.

You might want to read [1] and [2] (which says don't post using HTML).

[1] http://stackoverflow.com/questions/4716152/why-do-r-objects-not-print-in-a-function-or-a-for-loop
[2] http://www.R-project.org/posting-guide.html
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

capricy gao <capricyg at yahoo.com> wrote:
>
>
>I am just testing the possibility of using grep under for loop:
>
>>for(i in 1:10){grep("a",letters)}
>
>
>nothing came out;
>
>when I ran: 
>
>
>>grep("a",letters), 
>
>
>I got "1"
>
>so in my for loop, I expected to see ten "1"s, but I did not.
>
>Could anybody help me to figure out why? Thanks a lot for your help.
>
>Capricy
>	[[alternative HTML version deleted]]
>
>______________________________________________
>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