Re: [R] paste data

From: Hans-Joerg Bibiko <>
Date: Wed, 18 Jun 2008 11:01:32 +0200

On 18 Jun 2008, at 10:36, Sybille Wendel wrote:
> I need a command.
> I have a lot of data in different dataframes(auto.0a, auto.0b, auto.
> 0c, auto.5Na,...), that has similar names.
> I could print the names all at once wih a loop with the command
> paste(), see below:
> plot<-
> c("0a","0b","0c","5Na","5Nb","5Nc","PKa","PKb","PKc","5NPKa","5NPKb",
> "5NPKc","10NPKa","10NPKb","10NPKc","20NPKa","20NPKb","20NPKc")
> for (x in 1:length(plot))
> {
> name<-paste("auto.",plot[x],sep="")
> print(name)
> }

First of all, maybe it is better to avoid to name a variable 'plot'. It works, but it could be a bit confusing.

You can do this easier (paste can handle vectors etc.): name<-paste("auto.", plot, sep="")

> I want to do very similar things with all the dataframes and their
> structure is also the same.
> Is there a way to write a loop? (so that I don't have to write the
> same 18 times)
> I tried things like that:
> for (x in 1:length(plot))
> {
> plot(paste("auto.",plot[x],sep="")[,1],paste("auto.",plot[x],sep="")
> [,2],col=...)
> }

paste("auto.",plot[x],sep="")[,1] => doesn't work.

Assuming that 'auto.0a' is a data.frame you should use


instead to get the first column of the data.frame 'auto.0a'

Maybe try:

plot(get(paste("auto.",plot[x],sep=""))[,1], get(paste("auto.",plot[x],sep=""))[,2], col=...)

--Hans mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed 18 Jun 2008 - 09:08:37 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 18 Jun 2008 - 10:31:19 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive