[R] help with data import/export
Peter Dalgaard BSA
p.dalgaard at biostat.ku.dk
Thu Aug 31 15:21:24 CEST 2000
"Charles Raux" <Charles.Raux at let.ish-lyon.cnrs.fr> writes:
> Did you try R-Excel interface ?
> see http://lib.stat.cmu.edu/R/CRAN/contrib/extra/index.html
Hmm. Could be a bit of an overkill.
> Le 31 Aug 00 à 3:09, Jun Sung écrivait:
> > how can I import/export data from ms excel?
Here's what I'm planning to teach my students (Import only, to export
use write.table):
Sometimes one will want to move data between \R{} and other
statistical packages or spreadsheets. Work is in progress on support
for letting \R{} read and write the save formats of other packages,
but currently the easiest way remains to be to get the other package
to export data as a text file of some sort and use one of
|read.table|, |read.csv|, and |read.csv2| to read the data as an \R{}
data frame. Unfortunately, each program seems to have its own
idiosyncracies, but the read functions in \R{} are flexible enough to
cope. The current techniques for the three most common PC programs
are as follows. Slight variations of the tab-separated format seems
to be the common denominator. However, one should be careful in
sending such files by email since some mail programs will convert the
TAB characters to a number of spaces.
\begin{description}
\item[SPSS:] Use |File, Export| menu in the data editor and export as
a tab-separated file (for simplicity, say |mydata.txt| in the top
directory on the |C:| drive). Make sure that it contains a header
line with the variable names and use
|read.csv2("C:/mydata.txt",sep="\t")| to read it in. This refers to
locales where the comma is used as decimal separator, otherwise use
|read.csv|.
Alternatively, one can copy the data or a section of it directly to
a text editor such as Notepad via the Windows copy and paste
mechanism. Note however that the variable names are not copied in
this way, so one must either add them by hand (recommended) or use
|read.csv2("C:/mydata.txt",sep="\t",header=F)| and add variable
names later.
\item[Excel:] Use |File,Save as...| and choose tab-sep (|.txt|) or use
the clipboard. Subsequent data handling is similar to SPSS. Note
that a header line will only be present if it was in the spreadsheet
to begin with.
\item[SAS:] It is possible to export in a comma-separated or
tab-separated format. Notice that SAS will use |"."| for decimal
point irrespective of locale. The files can be read using
|read.csv("C:/mydata.csv")| or |read.csv("C:/mydata.csv",sep="\t")|.
The copy and paste technique does not work.
\end{description}
> > also is there a way to import/export data of the hdf format?
There's an hdf5 package which would seem to be functional on Windows.
> > is there a way to import/export hdf format for ms excel as well?
Wouldn't know...
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list