[R] Uploading CSV file into R

John Kane jrkrideau at yahoo.ca
Sat May 14 16:14:27 CEST 2011



--- On Fri, 5/13/11, Me <dollear1 at illinois.edu> wrote:

> From: Me <dollear1 at illinois.edu>
> Subject: Re: [R] Uploading CSV file into R
> To: r-help at r-project.org
> Received: Friday, May 13, 2011, 10:25 PM
> OK, I have another question if you
> guys don't mind helping again. I have all
> of the information I need in a csv file, and I've read the
> csv file into R,
> but I'm having some trouble manipulating it. In the past,
> I've always
> manipulated data that was premade for me in the class I'm
> in, so I think I'm
> probably formatting the csv file wrong.

No you don't have a csv file any more.  If you read in the data using something like read.csv(filename) then you have a data.frame not a csv file.

You need to get a feel for how  R handles data. It sounds like you're working mainly with a data.frame so I'd concentrate on them. Lists are handy but you really don't want to know.

These links may help you a bit: http://www.r-tutor.com/r-introduction/data-frame  and http://www.r-tutor.com/r-introduction/data-frame/data-frame-column-vector

There are a number of good tutorials on the R site.  To find them go to the R site, clink on CRAN, select a CRAN site.  Once selected you should see "Contributed" This links to some good material.

As a quick start have a look at Jim Lemon's Kickstarting R  direct linkk http://cran.skazkaforyou.com/

I would not recommend `Introduction to R`. It`s  a great document but I think it is too complicated for you at the moment.  





> 
> The data is a list of countries with information about
> their inbound
> tourism, homicide rate and GNI per capita. The file has
> four columns, with
> the first being the name of the country, then the year (all
> 2008 in this
> case), then homicide rate, then GNI, then inbound tourism.
> 
> My problem comes when I'm trying to separate the different
> the different
> categories. For example, I'll try to isolate GNI per capita
> by writing
> Data$GNI, but R doesn't seem to keep track of which country
> is assigned with
> which GNI score. When I write View(Data$GNI), I just get a
> table that has
> two columns: one column is the numbers 1 through 67, and
> the second is the
> GNI per capita for each country that is that number in the
> list.
> 
Yes, you are looking at the column you specified Data$GNI
WHat you have said to R is 'Open the data editor and Show me the column of data in data.frame Data that is named GNI'.
The numbers on the left are just the row numbers of the column.

You are not manipulating the data,youre simply in a data editor. You might use this is you had a type in the data.frame and need to make a change. 

If you want to get an idea of what the data looks like try something like head(Data) or perhaps head(Data, 20) to see a bit more of it.


> Can anyone help me correctly format the csv file 

It sounds like the file is correctly formatted and it is no longer a csv file. It`s a data frame, wich is a specific way of storing data in R.  You may be thinking that it would look like a spreadsheet file and it will not.

.or tell me
> what else I'm
> doing wrong? Thanks a lot.

Lots. 
 You`re trying to do things without having some basics understanding of how R works.  Depending on how much time pressure you`re under, it`s well worth taking a day or two and working through some of the tutorials mentioned above.



More information about the R-help mailing list