[R] Uploading CSV file into R

David Winsemius dwinsemius at comcast.net
Sat May 14 12:37:41 CEST 2011


On May 13, 2011, at 10:25 PM, Me wrote:

> 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.
>
> 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.

Not likely. More likely is that you have forgotten how to perform  
basic operations on dataframes. Type this at the console:

?Extract

> 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.

You should read the Introduction to R and work through the examples.  
At that point one would hope that you realize that you are just  
getting a vector of GNI from within your Data object.

>
> Can anyone help me correctly format the csv file or tell me what  
> else I'm
> doing wrong? Thanks a lot.

The problem would appear to be that you do not understand how to  
access an object and its components. I suspect you are no longer stuck  
at the point of getting a csv file. If I am correct then just typing:  
Data should produce the full table
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Uploading-CSV-file-into-R-tp3515237p3521623.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list