I just want to understand if there is a difference between names and colnames when working with data.frame. Both seems to behave the s
If you look at the beginning of the colnames and colnames<- functions source code :
R> colnames
function (x, do.NULL = TRUE, prefix = "col")
{
if (is.data.frame(x) && do.NULL)
return(names(x))
(...)
R> `colnames<-`
function (x, value)
{
if (is.data.frame(x)) {
names(x) <- value
}
(...)
You can see that for data frames, colnames just call the names function. So yes, they are strictly equivalent.