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 = "$") > Thanks, ANDREW
Do you mean something like:> paste(x$cat, collapse=" ")[1] "8 2 3 6 1" ?? Andy> From: Andrew Criswell > > 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 = "$") > > > > Thanks, > ANDREW
Andrew Criswell wrote:> 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^^^^^^^^^^^^^^ Same thing as ***what***????> below is obviously wrong > > > paste(x, cat, sep = "$") > >It's not at all clear what you want to do. Do you just wish to create the string ``x$cat''? This would be done via > paste("x","cat",sep="$") But why? It's a bad idea to use ``$'' in strings since ``$'' has a special meaning in R (i.e. to refer to components of lists). cheers, Rolf Turner rolf at math.unb.ca
On Mon, 12 Jul 2004 13:16:06 +0700, Andrew Criswell <r-stats at 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
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
Now that I see Duncan's reply, I believe that's what Andrew wanted. I really should read messages more carefully... Andy> From: Liaw, Andy > > Do you mean something like: > > > paste(x$cat, collapse=" ") > [1] "8 2 3 6 1" > > ?? > > Andy > > > From: Andrew Criswell > > > > 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 = "$") > > > > > > > Thanks, > > ANDREW > > ______________________________________________ > R-help at 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 > > > -------------------------------------------------------------- > ---------------- > Notice: This e-mail message, together with any attachments, > contains information of Merck & Co., Inc. (One Merck Drive, > Whitehouse Station, New Jersey, USA 08889), and/or its > affiliates (which may be known outside the United States as > Merck Frosst, Merck Sharp & Dohme or MSD and in Japan, as > Banyu) that may be confidential, proprietary copyrighted > and/or legally privileged. It is intended solely for the use > of the individual or entity named on this message. If you > are not the intended recipient, and have received this > message in error, please notify us immediately by reply > e-mail and then delete it from your system. > -------------------------------------------------------------- > ---------------- >