tags:

views:

64

answers:

2

Is there a reason why R won't allow me to have a number as the column name of my dataframe?

also noticed that if i do data.frame(XX) it adds an X to all the column headers that have numbers at the front.

+6  A: 

Yes, because R won't allow names of objects to start with numbers. If you were to call attach() with the data.frame, this would cause some issues.

You will notice (for example) in the read.table function the check.names parameter which uses the make.names() function to do what you describe.

Shane
Yup, I explained as much yesterday in relationship to data frame naming.
Dirk Eddelbuettel
Is there a reason for this? or is it just something that no-one really minds?It's not *that* big a deal to put X in front of any numbers i want to be headers, but I was just wondering WHY R won't let me.
Nathaniel Saxe
You *still* don't understand. Re-read Shane's answer, think about `attach()` and come to realize why these have to variable names. As Marek shows, you *could* do it but that doesn't mean you *should*.
Dirk Eddelbuettel
+3  A: 

Works for me

data.frame(`1`=rnorm(3), `2`=head(letters,3), check.names=FALSE)
#        1 2
# 1 0.5019 a
# 2 1.1148 b
# 3 0.4787 c
Marek