[R] Value lables, variable lables

loren mccarter lorenmc at socrates.berkeley.edu
Thu Nov 29 00:25:29 CET 2001


Yes, when I first made the switch from SPSS to SAS and R, I had the same
question. I quite liked the way SPSS did this. I also liked the
FileInfo menu option (I think that was the name of it), which essentially
supplied a verbose description of the data set based on the variable and
value labels. Here's some pointers to help with the transition: 

VALUE LABELS:

   See help(factor). The factor() function has a label option that allows
the setting of value labels for R factors (e.g., Gender; Ethnicity).

VARIABLE LABELS:
   
   I'm not aware of an exact equivalent. To name a field/variable/column 
in an R data frame, I use the names() function. R allows for long names
(even with spaces as long as you use quotes) and thus I haven't found
variable labels to be all that necessary. The old SPSS allowed only 8
characters and thus labels were necessary for files with lots of
variables. 

The only time that I *really* want a longer, descriptive label is when I'm
creating figures or tables, at which point I use the xlab/ylab options for
plot. For tables, I usually create a separate dataframe containing only
those data that will be in the table and use the names() function. In
other words work with short names for 90% of the time and use long names
in plots for the other 10% where I'm presenting results. 

Finally, when I used SPSS for work in psychology, I found that people
often stored large SPSS data files with lots (e.g., 3000) of variables
(columns) and a few (e.g., 200) observations (rows). In these situations,
variable labels were absolutely necessary. If you need to deal with such
an issue, I would recommend that you look into using R with an underlying
database (e.g., MySQL, PostgreSQL). Store the large SPSS file in the
database where every field can be fully documented in a database
table. Then, when the time comes to do an analysis requiring R, pull only
the relevant fields into R using the database connection.

I've found the R/Database combo to be a fully functional system where both
parts outperform the all-in-one systems such as SPSS and SAS. 

Loren


On Wed, 28 Nov 2001, Paul E Johnson wrote:

> I'm looking for an analogy to SPSS and "variable lable" and "value 
> lable" in R. I have a copy of S+4.0 and can't find any info in their 
> docs, and don't find it in R-intro either.
> 
> 
> In SPSS, for each variable, there is a name like
> 
> VAR001
> 
> and a variable lable (a longer descriptive string) like
> 
> Respondent ID
> 
> and for many of the values of other variables there are value lables.
> For example, VAR008 has the lable
> 
> GENDER of Respondent
> 
> and it has values of 0 and 1, and the values are labled
> 
> 0   Male
> 1   Female
> 
> Sometimes value lables are much longer strings.
> 
> Whenever a person runs a model in SPSS, the printout automatically finds 
> the lable and prints it along with the variable name and the values are 
> replaced by their lables.
> 
> In R, does one keep a list of variable lables and value lables? If so, 
> where?  It seems to me that an R collection type like Map or Hash would 
> be needed so one could put in a variable name and get back a lable.
> 
> -- 
> Paul E. Johnson                       email: pauljohn at ukans.edu
> Dept. of Political Science            http://lark.cc.ukans.edu/~pauljohn
> University of Kansas                  Office: (785) 864-9086
> Lawrence, Kansas 66045                FAX: (785) 864-5700
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list