Skip to content
Prev 132028 / 398506 Next

ls() pattern

Ok.  How's this?

#Generate variable names
varnames = paste("cbcname", 1:10, sep="")
#Assign them to values
for(i in 1:10) assign(varnames[i], 0.1*i)
#Form the middle bit of the command
cmd = paste(varnames, "=", mget(varnames, envir=.GlobalEnv), collapse=",")
#Evaluate the command
eval(parse(text=paste("df=data.frame(", cmd, ")", sep="")))

There's a general rule that says if you have to use parse, you're probably 
doing it the wrong way, but it's been a long day, so that's the best way I 
can think of right now.

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}
Message-ID: <OF77AD1A2C.66A22348-ON802573B0.00659533-802573B0.006616CD@hsl.gov.uk>
In-Reply-To: <BAY109-W33C23BAA40F065135FFF19E3660@hsl.gov.uk>