[R] creating expression with for-loop

Duncan Murdoch murdoch at stats.uwo.ca
Wed Apr 9 21:48:23 CEST 2008


On 4/9/2008 3:22 PM, Thomas Hoffmann wrote:
> Dear listmembers
> 
> I would like to create an expression that looks like
> 
> labl = expression(10^1,10^2,10^3,10^4,10^5)
> 
> using a for-loop. However
> 
> for (i in 1:5){ labl[i]=expression(10^i) }
> 
> does not do the right thing. Does anybody knows help?

labl <- expression()
for (i in 1:5) labl[[i]] <- bquote(10^.(as.numeric(i)))

(The as.numeric() might not be necessary if you don't care if the 
exponent prints as 1L, 2L, etc.  plotmath() handles it fine.)

Duncan Murdoch



More information about the R-help mailing list