Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在R中访问数据帧的名称_R - Fatal编程技术网

如何在R中访问数据帧的名称

如何在R中访问数据帧的名称,r,R,我的问题是如何获得数据帧的名称而不是colnames 例如,d是我的数据帧,我想使用一个函数来获取确切的名称“d”,而不是names(d) 非常感谢你 更新: 我之所以问这个问题,是因为我想编写一个函数,一次生成多个绘图。我需要改变主要的情节,以便区分它们。我的函数看起来像 fct=函数(数据){ cor_Max=cor(数据) 溶液=fa(r=cor_Max,nfactors=1,fm=“ml”) 返回(fa.diagram(解决方案,main=名称(数据)) } 如何更改函数中与数据名称相对

我的问题是如何获得数据帧的名称而不是colnames

例如,
d
是我的数据帧,我想使用一个函数来获取确切的名称“d”,而不是
names(d)

非常感谢你

更新:

我之所以问这个问题,是因为我想编写一个函数,一次生成多个绘图。我需要改变主要的情节,以便区分它们。我的函数看起来像
fct=函数(数据){
cor_Max=cor(数据)
溶液=fa(r=cor_Max,nfactors=1,fm=“ml”)
返回(fa.diagram(解决方案,main=名称(数据))
}


如何更改函数中与数据名称相对应的main?

您可以使用R允许您获得表达式的文本表示:

getName <- function(x) deparse(substitute(x))
print(getName(d))
# [1] "d"

getName您可以使用R允许您获取表达式的文本表示:

getName <- function(x) deparse(substitute(x))
print(getName(d))
# [1] "d"

getName您可以使用R允许您获取表达式的文本表示:

getName <- function(x) deparse(substitute(x))
print(getName(d))
# [1] "d"

getName您可以使用R允许您获取表达式的文本表示:

getName <- function(x) deparse(substitute(x))
print(getName(d))
# [1] "d"

getName
objects()
将列出您环境中的所有对象。请注意,问题中使用的
names()
提供了数据框的列名。

objects()
将列出您环境中的所有对象。请注意
names()问题中使用的
提供了数据框的列名。

对象()
将列出环境中的所有对象。请注意,问题中使用的
名称()
提供了数据框的列名。

对象()
将列出您环境中的所有对象。请注意,问题中使用的
名称()
,提供了数据框的列名。

最常用的方法是如Robert所示,使用
deparse(替换(x))
。 但是您可以尝试使用
match.call()


最为人接受的方法是,如Robert所示,使用
deparse(替换(x))
。 但是您可以尝试使用
match.call()


最为人接受的方法是,如Robert所示,使用
deparse(替换(x))
。 但是您可以尝试使用
match.call()


最为人接受的方法是,如Robert所示,使用
deparse(替换(x))
。 但是您可以尝试使用
match.call()


我阅读您的问题是为了说明您要查找的是数据帧的名称,而不是列名。因此,您要查找传递给fct的数据参数的名称。如果是这样,下面类似的内容可能会有所帮助

fct  <- function(data){
 cor_Max  <-  cor(data)
 # as.character(sys.call()) returns the function name followed by the argument values
 # so the value of the "data" argument is the second element in the char vector
 main <-  as.character(sys.call())[2]
 print(main)
 }

fct我读了你的问题,想说你是在寻找数据帧的名称,而不是列名。因此,你是在寻找传递给fct的数据参数的名称。如果是这样,也许下面类似的内容会有所帮助

fct  <- function(data){
 cor_Max  <-  cor(data)
 # as.character(sys.call()) returns the function name followed by the argument values
 # so the value of the "data" argument is the second element in the char vector
 main <-  as.character(sys.call())[2]
 print(main)
 }

fct我读了你的问题,想说你是在寻找数据帧的名称,而不是列名。因此,你是在寻找传递给fct的数据参数的名称。如果是这样,也许下面类似的内容会有所帮助

fct  <- function(data){
 cor_Max  <-  cor(data)
 # as.character(sys.call()) returns the function name followed by the argument values
 # so the value of the "data" argument is the second element in the char vector
 main <-  as.character(sys.call())[2]
 print(main)
 }

fct我读了你的问题,想说你是在寻找数据帧的名称,而不是列名。因此,你是在寻找传递给fct的数据参数的名称。如果是这样,也许下面类似的内容会有所帮助

fct  <- function(data){
 cor_Max  <-  cor(data)
 # as.character(sys.call()) returns the function name followed by the argument values
 # so the value of the "data" argument is the second element in the char vector
 main <-  as.character(sys.call())[2]
 print(main)
 }

fct但当dataframe是函数中的参数时,它实际上似乎不起作用,请参阅updatebut当dataframe是函数中的参数时,它实际上似乎不起作用,请参阅updatebut当dataframe是函数中的参数时,它实际上似乎不起作用,请参阅updatebut它实际上似乎不起作用当dataframe是函数中的参数时,它不起作用,请参见updateJust a note,
names
不仅仅用于列名。它也可以用于向量。只需注意,
names
不仅仅用于列名。它还可以用于向量。只需注意,
names
不仅仅用于列名。它可以也用于向量。请注意,
names
不仅仅用于列名。它也可以用于向量。hi@RichardScriven请查看我的更新我知道如何在整个环境中获取数据帧的名称,但我不知道如何在函数中访问它。hi@RichardScriven请查看我的更新我知道如何获取名称,但我不知道如何在函数中访问它。hi@RichardScriven请查看我的更新我知道如何在整个环境中获取数据帧的名称,但我不知道如何在函数中访问它。hi@RichardScriven请查看我的更新我知道如何在函数中获取数据帧的名称整体环境,但我不知道如何在函数中访问它。