Reputation: 69
I want to change my code's data.frame.s name. But i have problem to work it.
A<-function(x){
data.frame(max(x),min(x))
}
x<-c(1,2,3,4,5,5,4,3,2,1)
A(x)
names(A(x))
names(A(x))<-c("max","min")
It always appear Error in names(A(x)) <- c("max", "min") : could not find function "A<-" How could i change the A(x)'s names?
Upvotes: 1
Views: 1548
Reputation: 521629
You need to use the names()
function directly on the data frame. To do this, first assign your data frame to a variable, then change the column names.
df <- A(x)
names(df) <- c("max","min")
> df
max min
1 5 1
Upvotes: 2