[R] printing text within if functions inside a for loop

Mario Valle mvalle at cscs.ch
Tue Mar 23 09:54:13 CET 2010


Use:
	cat(sprintf("Long on %s at a price of %f\n",dates[j],data[j]))

Hope it helps
		mario

Tian Pan wrote:
> Hi
> 
> I am having a problem with outputting text inside an if function. I have the
> following code:
> 
> for (j in 20:length(bb.up))
> {
>  if (up[j]==1 && up[j-1]==0)
>  {
>   sprintf("Long on %s at a price of %f",dates[j],data[j])
>  }
>  if (down[j]==1 && down[j-1]==0)
>  {
>   sprintf("Short on %s at a price of %f",dates[j],data[j])
>  }
> }
> 
> The loop runs fine and the sprintf function runs fine on its own, but the
> problem I am having is that there is no output if I run the loop with the
> sprintf inside it. Does anyone know what could be wrong? Is there a way for
> the code to output data within this loop? I can't seem to find anything on
> the internet for this problem.
> 
> Thanks in advance.

-- 
Ing. Mario Valle
Data Analysis and Visualization Group            | http://www.cscs.ch/~mvalle
Swiss National Supercomputing Centre (CSCS)      | Tel:  +41 (91) 610.82.60
v. Cantonale Galleria 2, 6928 Manno, Switzerland | Fax:  +41 (91) 610.82.82



More information about the R-help mailing list