I’m have a data frame without columns:
df<-data.frame(v1=c(1:10), v2=seq(1, 100, length=10))
I want to change the header names to “X” and “Y”
I know I can do this using:
names(df)<-c("X","Y")
What I would like to do is write a function where I could pass a data frame as an argument, and place the headers with these header names.
I’ve tried:
get.names<- function(x)
{names(x)<-c("X", "Y")}
Thanks in advance for any help.
Your function sets the names; you just need to return the object.
Alternatively, you could use the
setNamesfunction