[R] variable name question

Rolf Turner rolf.turner at xtra.co.nz
Mon Oct 10 03:43:26 CEST 2011


On 10/10/11 04:53, R. Michael Weylandt wrote:

<SNIP>
> Try this:
>
> for (i in 1990:2009) {
>      varName = paste("pci", i, collapse = "")
>      assign(varName, log(get(varName))
> }
>
<SNIP>

I believe that ``sep= " '' is needed here rather than collapse.

Try:
         paste("junk",42,collapse="")

You get

     [1] "junk 42"

with a space in it.  Here paste is using the default value of sep, 
namely " ",
and is not using collapse at all, since there is nothing to collapse (the
value is a scalar to start with).

Whereas

         paste("junk",42,sep="")

gives

     [1] "junk42"

which is what is wanted.

     cheers,

         Rolf Turner



More information about the R-help mailing list