简体   繁体   中英

Change the data.frame's name in R

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM