[R] Assigning Data a name from within another variable?

baptiste auguie ba208 at exeter.ac.uk
Mon Jun 15 18:34:31 CEST 2009


Kenny Larsen 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
>   
Hi,

have you checked the r wiki,

http://wiki.r-project.org/rwiki/doku.php?id=guides:assigning-variable-names

this page is a really a work in progress, feel free to add comments.

HTH,

baptiste




More information about the R-help mailing list