[R] How to use macro variable in a text string
David Winsemius
dwinsemius at comcast.net
Thu Jul 23 00:30:23 CEST 2009
On Jul 22, 2009, at 5:46 PM, kxk wrote:
>
> I want to use read.table to input many files, each for a different
> year. I
> would like to use the macro variable 't' to refer to the exact file
> that I
> would like to input the data using read.table. How could I do
> this? Thank
> you!
>
> for (t in 1970:2005)
> { edge <- read.table(file="edge_t.csv", header=T, sep=",")
Pretty sure that will not work. Take a look at the paste function for
putting together strings and values.
paste("test", 1:3, sep="")
#[1] "test1" "test2" "test3"
And you might consider whether you want "edge" to be wiped out the
next time through the loop, too. That is what would happen with your
current construction.
> ## I will have many rows of code following the read.table line
> }
>
> --
David Winsemius, MD
Heritage Laboratories
West Hartford, CT
More information about the R-help
mailing list