Skip to content
Prev 361154 / 398506 Next

Sprintf to call data frame from environment

Hi Beatriz,
I'll guess that you have a number of files with names like this:

Samples_1.txt
Samples_2.txt
...

Each one can be read with a function like read.table and will return a
data frame with default names (V1, V2, ...). You then want to extract
the first element (column) of the data frame. If I'm correct, try
this:

V1s<-list()
# nfiles is the number of files you want to read
for(i in 1:nfiles) {
 filename<-paste("Samples_",i,".txt,sep="")
 # you will probably have to add the appropriate arguments to read.table
 V1s[[i]]<-read.table(filename)$V1
}

The list V1s should contain the first columns of all the data frames read.

Jim
On Wed, May 25, 2016 at 7:01 AM, Beatriz <aguitatierra at hotmail.com> wrote: