[R] Working with data frames

Ivan Calandra ivan.calandra at univ-reims.fr
Thu Dec 11 14:08:38 CET 2014


Hi Sun,

If I understood correctly (a reproducible example would be of great 
help), it seems you're struggling with factors. Read on this topic to 
better understand how it works.

For your plots, you would need to set the labels with the argument 
'xlab' for plot(). To access the names of the factors, use levels()

HTH,
Ivan

--
Ivan Calandra, ATER
University of Reims Champagne-Ardenne
GEGENA² - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calandra at univ-reims.fr
https://www.researchgate.net/profile/Ivan_Calandra

Le 11/12/14 14:00, Sun Shine a écrit :
> Hello
>
> 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.
>
> Cheers
> Sun
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



More information about the R-help mailing list