[R] help with paste

Marc Schwartz MSchwartz at MedAnalytics.com
Mon Jul 12 16:04:18 CEST 2004


On Mon, 2004-07-12 at 01:16, Andrew Criswell wrote:
> Hello All:
> 
> Suppose the following little data frame:
> 
>  > x <- data.frame(dog = c(3,4,6,2,8), cat = c(8,2,3,6,1))
>  >
>  > x$cat
> [1] 8 2 3 6 1
>  >
> 
> How can I get the paste() function to do the same thing. The command 
> below is obviously wrong
> 
>  > paste(x, cat, sep = "$")


You need to quote the "x" and the "cat" as explicit names, otherwise the
objects 'x' and 'cat' are passed as arguments. 'x' in this case being
your data frame and 'cat' being the function cat().

Try this:

> eval(parse(text = paste("x", "cat", sep = "$")))
[1] 8 2 3 6 1

HTH,

Marc Schwartz




More information about the R-help mailing list