I have a R dataFrame df with the following:
time value reference
45 10 11
22 12 10
13 15 5
I would like to replace the last column of the dataFrame to obtain:
time value space
45 10 11
22 12 10
13 15 5
I tried this:
colnames(length(colnames(df)))<-"space"
but it does not work. How can I do it?
The following should do what you need:
colnames(df)[ncol(df)] <- "space"
Marginally less typing:
names(df)[ncol(df)] <- "space"
You can use names()
instead:
names(df)[length(names(df))]<-"space"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With