[R] Bug in colnames of data.frames?
Arne Henningsen
ahenningsen at email.uni-kiel.de
Tue Aug 17 16:01:42 CEST 2004
Hi,
I am using R 1.9.1 on on i686 PC with SuSE Linux 9.0.
I have a data.frame, e.g.:
> myData <- data.frame( var1 = c( 1:4 ), var2 = c (5:8 ) )
If I add a new column by
> myData$var3 <- myData[ , "var1" ] + myData[ , "var2" ]
everything is fine, but if I omit the commas:
> myData$var4 <- myData[ "var1" ] + myData[ "var2" ]
the name shown above the 4th column is not "var4":
> myData
var1 var2 var3 var1
1 1 5 6 6
2 2 6 8 8
3 3 7 10 10
4 4 8 12 12
but names() and colnames() return the expected name:
> names( myData )
[1] "var1" "var2" "var3" "var4"
> colnames( myData )
[1] "var1" "var2" "var3" "var4"
And it is even worse: I am not able to change the name shown above the 4th
column:
> names( myData )[ 4 ] <- "var5"
> myData
var1 var2 var3 var1
1 1 5 6 6
2 2 6 8 8
3 3 7 10 10
4 4 8 12 12
I guess that this is a bug, isn't it?
Arne
More information about the R-help
mailing list