Use a 'list' to read in the data and access it:

files<-list.files()
files<-files[grep('.wm4', files)]
labels<-gsub('.wm4', '',files)

myInput <- lapply(files, read.table)
# if you want to get rid of .wm4
names(myInput) <- sub(".wm4$", "", names(myInput))

On Mon, Jun 15, 2009 at 11:50 AM, Kenny Larsen <k.larsen@sheffield.ac.uk>wrote:

>
> Hi All,
>
> I have hunted high and low and tried dozens of things but have yet to
> achieve the result I require. Below is my code (taken mostly from another
> thread on here) thus far:
>
> files<-list.files()
> files<-files[grep('.wm4', files)]
> labels<-gsub('.wm4', '',files)
>
> for(i in 1:length(files)){
> X<-read.table(files[i])
> <My problem is here!>
>
> What I am trying to do now is assign the first item in labels in place of X
> so the table name will effectively be whatever is written in labels[1]. The
> files simply consist of two columns of real numbers. I have tried several
> things, such like replacing X with labels[1], but this simply writes the
> data in one long column to the first place of labels(which makes sense).
> How
> do I extract what is in labels[1] and set it as the table name?
>
> As always any help is greatly appreciated.
>
> Kenny Larsen
> --
> View this message in context:
> http://www.nabble.com/Assigning-Data-a-name-from-within-another-variable--tp24037279p24037279.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

	[[alternative HTML version deleted]]


