Re: [R] help with paste

From: Duncan Murdoch <dmurdoch_at_pair.com>
Date: Mon 12 Jul 2004 - 23:59:36 EST

On Mon, 12 Jul 2004 13:16:06 +0700, Andrew Criswell <r-stats@arcriswell.com> 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 = "$")

I'm not 100% sure I know what the "same thing" is, but I think you want

 eval(parse(text=paste("x", "cat", sep="$")))

The parse() function converts the string to an expression, and the eval() function evaluates it. You can use variables in place of "x" and "cat" if you want, e.g.

 animal <- "dog"
 eval(parse(text=paste("x", animal, sep="$")))

Duncan Murdoch



R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 13 00:10:13 2004

This archive was generated by hypermail 2.1.8 : Wed 03 Nov 2004 - 22:54:50 EST