Dear all,
I have a lot of data files (.txt) that I want to read in all at once, if
possible.
the files have names in time system. for example: RA940101, RA940102,
RA940103, RA940104 an so on.
(meaning: RA, year:91, month: here january, day of the month.)
I tried something like
vektor <- c("RA940101","RA940102","RA940103")
for (x in 1:3)
{ data <- read.table(paste(vektor[x],sep=""),header=F) }
But how can I put the vektor on the left side, so that data would be instead
of data the three first days of the year 1994?
best wishes and thanks a lot for your answers,
Sybille
[[alternative HTML version deleted]]
Hi,
Try this,
files <- paste("RA94010",1:3,sep="")
# or files <- list.files(pattern = "RA94010")
list.of.data <- lapply(files, read.table, header=F)
# if required, collapse into a single data.frame
do.call(rbind, list.of.data)
HTH,
baptiste
2009/10/28 Sybille Wendel <wendel.sybille at
googlemail.com>:> Dear all,
>
> I have a lot of data files (.txt) that I want to read in all at once, if
> possible.
> the files have names in time system. for example: RA940101, RA940102,
> RA940103, RA940104 an so on.
> (meaning: RA, year:91, month: here january, day of the month.)
>
> I tried something like
>
> vektor <-
c("RA940101","RA940102","RA940103")
>
> for (x in 1:3)
> { data <- read.table(paste(vektor[x],sep=""),header=F) }
>
> But how can I put the vektor on the left side, so that data would be
instead
> of data the three first days of the year 1994?
>
> best wishes and thanks a lot for your answers,
>
> Sybille
>
> ? ? ? ?[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
On Wed, Oct 28, 2009 at 9:38 AM, Sybille Wendel <wendel.sybille at googlemail.com> wrote:> Dear all, > > I have a lot of data files (.txt) that I want to read in all at once, if > possible. > the files have names in time system. for example: RA940101, RA940102, > RA940103, RA940104 an so on. > (meaning: RA, year:91, month: here january, day of the month.) > > I tried something like > > vektor <- c("RA940101","RA940102","RA940103") > > for (x in 1:3) > { data <- read.table(paste(vektor[x],sep=""),header=F) } > > But how can I put the vektor on the left side, so that data would be instead > of data the three first days of the year 1994?Store in a list: data = list() for(x in 1:3){ data[[vektor[x]]] = read.table(.......) } then you can do data[["RA940101"]] to get that set of data. You can also do this by number: data[[x]] = read.table(....) and then get data[[1]], data[[2]] etc etc. See any basic R help/tutorial for more information about 'lists'. Barry