Hi all. What is "print print print"? I don't see output of the print command in for loop and have found this link: http://stackoverflow.com/questions/1816200/chisq-test-doesnt-print-results-when-in-a-loop It describes a problem, similar to mine. My problem. I want to execute print command in for loop. If I copy for loop body with print() and paste it to console, I don't see any output. If I type the command, I do see the output. If I paste the command by parts I also see the output. If I construct the command by picking parts of the history with the up arrow, I also don't see any output. Search for "print print print" still didn't bring anything useful. -- Best regards, Vladimir mailto:wl2776 at gmail.com
On Dec 5, 2012, at 5:03 AM, Vladimir eremeev wrote:> Hi all. > > What is "print print print"? > > I don't see output of the print command in for loop and have found > this > link: > http://stackoverflow.com/questions/1816200/chisq-test-doesnt-print-results-when-in-a-loop > > It describes a problem, similar to mine. > My problem. I want to execute print command in for loop. > > If I copy for loop body with print() and paste it to console, I > don't see > any output.Code we, want code.> > If I type the command, I do see the output. > If I paste the command by parts I also see the output. > > If I construct the command by picking parts of the history with the up > arrow, I also don't see any output.Code?> > Search for "print print print" still didn't bring anything useful.The questioner on SO was executing "print chisq.test print" and he was advised (and apparently understood ) that he need to be executing "print print print". Get it now? If you have a specific problem to be addressed then you should post the code, but I think using Rhelp to explain cryptic answers on SO might be expecting a bit much. -- David Winsemius, MD Alameda, CA, USA
On 12/06/2012 12:03 AM, Vladimir eremeev wrote:> Hi all. > > What is "print print print"? > > I don't see output of the print command in for loop and have found this > link: > http://stackoverflow.com/questions/1816200/chisq-test-doesnt-print-results-when-in-a-loop > > It describes a problem, similar to mine. > My problem. I want to execute print command in for loop. > > If I copy for loop body with print() and paste it to console, I don't see > any output. > > If I type the command, I do see the output. > If I paste the command by parts I also see the output. > > If I construct the command by picking parts of the history with the up > arrow, I also don't see any output. > > Search for "print print print" still didn't bring anything useful. >Hi Vladimir, Your problem is twofold. First, the print command simply tries to display whatever is passed as the first argument to it. Invoking: print() prints nothing, as there is nothing passed to display. Second, the print command is often used in R scripts because most functions will display their return values when invoked directly in the R console, but not when invoked within a "for" loop. The problem that you mentioned was due to the chisq.test function displaying its return value on its own, but not within the loop. The "print print print" comment was intended to mean: print(rownames(cl.vs.Onerall)[i]) print(chisq.test(observed, p=expected.fr)) print("------------------------------") in the loop so that the successive return values would be displayed. Try it for yourself with this simple example: x<-1:5 length(x) for(i in 1:3) length(x) for(i in 1:3) print(length(x)) Jim