[R] Working with data frames

Sun Shine phaedrusv at gmail.com
Thu Dec 11 14:00:04 CET 2014


I am struggling with data frames and would appreciate some help please.

I have a data set of 13 observations and 80 variables. The first column 
is the names of different political area boundaries (e.g. MHad, LBNW, 
etc), the first row is a vector of variable names concerning various 
census data (e.g. age.T, hse.Unk, etc.). The first cell [1,1] is blank.

I have loaded this via read.csv('path.to/data.set.csv'), and now want to 
run some analyses on this data frame. If I want to get a list of the 
names of the political areas (i.e. the first column), the result is a 
vector of numbers which appear to correlate with the factors, but I 
don't get the text names, just the corresponding number. So, if I want 
to plot something basic, like the area that uses the most gas for 
central heating, for example:

 > plot(data.set$ch.Gas)

The result is the y-axis gives the gas usage for the areas, but the 
x-axis gives only the numbers of the areas, not the names of the areas 
(which is preferred).

So, two questions:

(1) have I set up my csv file correctly to be read as a data frame as 
the first row of all of the remaining columns with the values for that 
political area in the corresponding row in the column with the specific 
variable name? So far, looking through tutorials and books seems to 
suggest yes, but at this point I'm no longer sure.

(2) How can I access the names of the political areas when plotting so 
that these are given on the x-axis instead of the numbers?

Thanks for any help.


More information about the R-help mailing list