s-news
[Top] [All Lists]

Re: Importing multiple .xls files?

To: Sarah Henderson <sarah.henderson@ubc.ca>
Subject: Re: Importing multiple .xls files?
From: Spencer Graves <spencer.graves@pdf.com>
Date: Sat, 16 Jul 2005 19:36:42 -0700
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <6.0.3.0.2.20050716181527.01f1d588@mail.interchange.ubc.ca>
References: <6.0.3.0.2.20050716181527.01f1d588@mail.interchange.ubc.ca>
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax)
1. Produce vectors of character strings with the names of the *.xls files and of the target data.frames you want to create. For example, the following will "station60", "station61", ..., "station800":

          DFname <- paste("station", 60:800, sep="")

You can then delete the ones that don't exist. Then convert this to file names as follows:

          Fname <- paste(DFname, ".xls", sep="")

Alternatively, copy the results of a "dir" into Excel, strip away what you don't want, save the names of the files you want to import, and delete the ".xls" with something like the following:

Period <- regexpr("\\.", Fnames)
DFnames <- substring(Fnames, 1, Period-1)

2. Use the GUI File -> "Import Data" -> "From File" dialog process for the first of the files.

3. Window -> History -> Display -> OK. Then copy the "guiImportData" command into a script file in a loop, replacing the FileName argument with Fname[i] and the TargetDataFrame arguments with DFname[i]. Set i <- 1, and try it until you get it to work. Then try i <- 1+i, and try it again. After you think you have all the options like you want them, you can get the rest in a loop.

          spencer graves

Sarah Henderson wrote:


Hello to all and, once again, my apologies for what is probably a very novice question.

I have a folder full of 300 .xls files that I need to import into S-Plus. All files have the same name structure (eg. 'station*.xls' where the * is some number between 60 and 800). Is there any way in which the import.data function can be written for a batch import these files? Or can I write my own function that calls import.data and passes a file name as the parameter? I have been experimenting (quite blindly) with possible alternatives, but nothing has worked out so far. Any suggestions will be greatly appreciated.

Once again, I'm working with S-Plus 6.2 (student edition) in a Windows XP platform.

Many thanks,

Sarah

--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news

--
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves@pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915

<Prev in Thread] Current Thread [Next in Thread>