I have a dataframe conformed for two columns, the first (column = 0) and the second (column = 1). I am trying to name zero column but I am into some difficulties. When I apply the
R, the indexing starts with 1. The column we were talking about is just
row.names. If we want to have 2 columns, we can create a new column 'Identification' from the rownames using
df1<- `row.names<-`(transform(dataexample, Identification = row.names(df1))[2:1], NULL)
Of course, it can be done in two steps like the one showed in the comments under OP's post. But, I posted a one-liner in case it is useful.
If we are using packages, one option with
data.table would be to change the default setting of
library(data.table) setnames(setDT(dataexample, keep.rownames = TRUE), 1, "Identification")