Cross Validated is a question and answer site for people interested in statistics, machine learning, data analysis, data mining, and data visualization. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Good variable names are:

a) short / easy to type,

b) easy to remember,

c) understandable / communicative.

Am I forgetting anything? Consistency is something to look for. The way I would put it is that consistent naming conventions contribute to the qualities above. Consistency contributes to (b) ease of recall and (c) understandability, though other factors are often more important. There is a clear tradeoff between (a) name length / ease of typing (e.g. all lowercase) and (c) understandability.

I'm investing a fair bit of thought in these issues because thousands of people are using the data and I hope many will use my code to prepare the data and facilitate some types of analysis. The data, from the Longitudinal Study of Adolescent Health, is broken down into multiple datasets. My first step was to take the 227 variables in the most commonly used dataset, recode them, give them more meaningful names. Original variable names are things like "aid", "s1", "s2", which I renamed "aid2", "age", and "". There are thousands of other variables in the other datasets which may be merged depending on what the researcher's goals are.

As long as I'm renaming variables, I want to make them as useful as possible. Here are some of the issues I've considered. So far, I have only used lower-case and avoided using any dashes or underscores, and I've only used periods for one very specific purpose. This has the virtue of simplicity and consistency, and causes no problems for most variables. But as things get more complex I'm tempted to break my consistency. Take, for example, my variable "talkprobmsum", it would be easier to read as "talkProbMSum" or better still "talk.prob.m.sum", but if I'm going to use capital letters or periods to separate words then shouldn't I do it for all variables?

Some variables are recorded at more than one time, e.g. the race variables so I appended .is or .ih to indicate whether they come from the in-school or in-home questionnaire. But there are surely some repeats I'm not aware of yet, would it be better to append a reference to the dataset to the name of every variable?

I need to group-center and standardize a lot of variables, the way I've done that is by appending .zms meaning z-score by male and by school.

Any general or specific thoughts or resources are greatly appreciated. See this repository for some of my code, and descriptive statistics with a list of variable names. I briefly described the reason for sharing this code here, and it was publicized a bit here, but these last two links aren't really relevant to the issue of variable naming conventions. Added: I edited this lightly, mostly just moving a paragraph, to try to avoid some of the confusion evident in the comments. Thanks for thoughts!

share|improve this question
+1 for setting up a public repository to share amongst researchers, although this question really belongs to Stack Overflow. – nico Apr 18 '12 at 17:28
Why would this question be better on SO, @nico? To me it does not appear to be about programming or even about R, but rather about appropriate practices for documenting and using data. – whuber Apr 18 '12 at 17:39
@whuber: I get your point. However, reading the question I saw it as "how should I call my variables?", which to me sounds more like a programming matter and not about statistics... On second thought, it is also true that the audience here is closer to that which will use the actual data than that of SO. – nico Apr 18 '12 at 18:13
+1, I think this is a great question & kudos for doing this – gung Apr 19 '12 at 2:41

The best response to this question is to duck it. Fundamentally, it doesn't much matter what the short names of the variables are as long as they are well documented in a codebook somewhere. Alas, since R has no native resources for this, people tend not to bother. (The lack is, for me, the single biggest failing in the language as a statistical tool).

There are various R packages providing this machinery, e.g. Hmisc which you use, and memisc. But really the best option is to make the whole thing into an R package. That way the processed data can be an object with a corresponding help page that describes what everything is now called and can assign credit where it's due. The package can also expose the raw data and your processing functions for people to see what you did to make the final product.

Also, a suggestion: don't include derived data like variables and their z-scored versions in the final data object at all if you can help it, just provide the functions to make it instead. Derived data is just trouble from the data management point of view.

share|improve this answer
You say that the variable names don't matter much as long as they are well documented... I don't want to make a mountain out of a mole-hill, but I do think they matter to some degree. Variable names which are hard to remember or hard to type have a real cost in researcher-time. Especially if the same variable names are being used by a thousand researchers. Thanks for your other pointers though :) – Michael Bishop Apr 19 '12 at 20:12

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.