[英]Change the data.frame's name in R
I want to change my code's data.frame.s name. 我想更改代码的data.frame.s名称。 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? 总是出现name(A(x))<-c(“ max”,“ min”)错误:找不到函数“ A <-”我如何更改A(x)的名称?
You need to use the names()
function directly on the data frame. 您需要直接在数据框上使用
names()
函数。 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.