Suppose I have a dataframe:
a <- data.frame(a=c("f", 2, 3), b=c("g", 3, 7), c=c("h", 2, 4))
and I would like to create column names from the first row. MY guess was:
names(a) <- a[1,]
which gives:
names(a)
[1] "3" "3" "3"
I did not fully get what is happening. Can anyone explain and help me on how to do it the right way?
Try this:
The columns of a are factors with each column having different levels. R casts them to ints. Since, for each column the letter appears last alphanumerically it gets assigned the value 3.
Try