I am just starting with R and encountered a strange behavior: when inserting the first row in an empty data frame, the original column names get lost.
a<-data.frame(one = numeric(0), two = numeric(0))
# one two
#<0 rows> (or 0-length row.names)
# "one" "two"
# X5 X6
#1 5 6
# "X5" "X6"
As you can see, the column names one and two were replaced by X5 and X6.
Could somebody please tell me why this happens and is there a right way to do this without losing column names?
A shotgun solution would be to save the names in an auxiliary vector and then add them back when finished working on the data frame.
I created a function which gathers some data and adds them as a new row to a data frame received as a parameter. I create the data frame, iterate through my data sources, passing the data.frame to each function call to be filled up with its results.