[R] csv vs. data frame
Gavin Simpson
gavin.simpson at ucl.ac.uk
Fri Aug 20 00:11:52 CEST 2010
On Thu, 2010-08-19 at 14:02 -0700, r.ookie wrote:
> I agree with you Duncan because I sense the hostility too, but, in any
> environment, there are going to be those who 'don't play well with
> others.' I just delete and read the next posting. I'm personally here
> to learn :)
If you knew Bert's contributions to this list (and No, I don't know him
personally), linking him with "those who 'don't play well with others.'"
is way off mark.
There is an increasing tendency for this list to be the first, only and
instant avenue of support for anyone using R. One could argue that
Bruce's question was sufficiently basic that had he read the posting
guide, which points to the manual Bert mentioned, he could have answered
his question with 5 minutes of locating/downloading and ten minutes
reading. Yet the question came here.
Yes, I agree that this list must remain civil and be a place that is
welcoming of new users, but it is frustrating when such questions are
asked after people (not me) have gone to the trouble of writing
documentation that explains the answers and posters don't bother to read
it.
Bruce; to link Bert's and Duncan's replies, it is easy to read data
stored as CSV data into R. As CSV files can be read by external software
such as MS Excel and OpenOffice.org leaving source data in this format
is probably preferable to importing to a data frame and then saving out
the R representation of this data frame object.
The read.csv() function is designed for this purpose. It will result in
a data frame (an object of class "data.frame") in the global
environment/workspace if assigned to an object name:
foo <- read.csv("foo.csv")
If your users are from European countries where "," is the decimal and
CSV file fields are separated by ";", then the read.csv2() function
should be used instead. Or cook your own via read.table().
Read the relevant section of An Introduction to R:
http://cran.r-project.org/doc/manuals/R-intro.html#Data-frames
so you get a feel for what data frames are in R, and also look at the
help for read.csv() (?read.csv executed from an R prompt) to learn how
non-numeric data is interpreted by R; for example, character data may be
imported as a factor in R, which may not be what you/your users want.
Arguments to read.csv() and the underlying read.table() function allow
you to control this.
HTH
G
> On Aug 19, 2010, at 1:42 PM, Duncan Murdoch wrote:
>
> On 19/08/2010 4:15 PM, Bert Gunter wrote:
> > Do not post such questions to this list.
> > Read an Introduction to R first, please.
> >
>
> I think that's a bit harsh: Bruce is trying to help R users, but doesn't necessarily want to learn to be one.
> > -- Bert
> >
> > On Thu, Aug 19, 2010 at 12:55 PM, Bruce Como <bruce at lmcsoftware.com> wrote:
> > > Hi,
> > >
> > > I am neither a statistician nor a user of R. I am a programmer trying to
> > > provide my users (both statisticians and R users) data in a format that
> > > works best for them.
> > >
> > > What is a data frame? Is source data easier to work with in this format or
> > > a csv file? Or yet another format?
> >
>
> A data frame is an internal structure in R. If you produce data in a csv file, it is easy for an R user to import it into a data frame. Take the usual care
> with quotes, commas, etc. within strings in the file.
>
> Duncan Murdoch
>
> > >
> > > Thanks for your time.
> > >
> > > Bruce
> > >
> > >
> > > [[alternative HTML version deleted]]
> > >
> > > ______________________________________________
> > > R-help at r-project.org mailing list
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> > >
> >
> >
> >
> >
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Dr. Gavin Simpson [t] +44 (0)20 7679 0522
ECRC, UCL Geography, [f] +44 (0)20 7679 0565
Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/
UK. WC1E 6BT. [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list