[R] basic programming question

Randy Zelick zelickr at pdx.edu
Thu Apr 15 17:08:14 CEST 2004


Hello list,

I am just starting to write some R functions (R 1.8 and Windows XP) and
got stuck as described below:

We have a bunch of time series data files, each is about 10,000 values.
There is a 12-line header in each one. I can read them and plot them
easily with R, but I want to make an automated system to read all the
files in a folder and have them appear as R objects that I can assemble in
different plots, or analyze together.

Perhaps this would be best done reading into a data table, where each row
is one of the files and each row extends for 10,000 columns? Or perhaps as
a matrix? I could use advice on that. My first notion, though, was just to
have them be individual files.

I started as follows:

#
# build a path from its parts:
#
p1="C:"
p2="Work-PSU"
p3="Lab-People-and-Projects"
p4="Dane"
p5="2004-04-06"
pt=file.path(p1,p2,p3,p4,p5,fsep="/")
#
lf<-list.files(pt)
ff="files"
sayfiles=paste(length(lf),ff,sep=" ")
#
# at this point if I type "sayfiles" I get "30 files" printed at the
console. OK, this is progress.
#
# Now I want to cycle through all the files and read in each one. The
# code here almost works, but I don't know how to do in R the simple task
# of substituting the read file name as the data object name.
#
d=dir(pt)
for (i in d){d[i]=scan(paste(pt,i,sep="/"),skip=12)} # this almost works
#

I know this is wrong, I just want to show my intention -- that is on each
iteration of the loop have a new R object made called d[i], the name of
the current file. This new object is then the result of the scan operation
on the file of that same name.

Thanks,

=Randy=

R. Zelick				email: zelickr at pdx.edu
Department of Biology			voice: 503-725-3086
Portland State University		fax:   503-725-3888

mailing:
P.O. Box 751
Portland, OR 97207

shipping:
1719 SW 10th Ave, Room 246
Portland, OR 97201


R. Zelick				email: zelickr at pdx.edu
Department of Biology			voice: 503-725-3086
Portland State University		fax:   503-725-3888

mailing:
P.O. Box 751
Portland, OR 97207

shipping:
1719 SW 10th Ave, Room 246
Portland, OR 97201




More information about the R-help mailing list