R cor 更改变量名称
R cor changes variables names
我注意到 R 会更改列名,而这些列名可能是参数。例如
foo.df <- data.frame("for" = rnorm(100,0,1), "else"=rnorm(100,2,0.1))
foo.cor.df <- cor(foo.df)
结果矩阵中的列名是 "for." 和 "else.",后缀为句点。这有记录吗?除了清理新列名称之外,还有其他解决方案吗?
for
和 else
是 R 中的保留字,将它们用作数据帧中的名称是无效的。请参阅 ?data.frame
和 check.names
参数,它将您引导至 ?make.names
,其中包含:
Details:
A syntactically valid name consists of letters, numbers and the
dot or underline characters and starts with a letter or the dot
not followed by a number. Names such as ‘".2way"’ are not valid,
and neither are the reserved words.
注意最后一行。
已添加附加的 .
以使名称有效。
我注意到 R 会更改列名,而这些列名可能是参数。例如
foo.df <- data.frame("for" = rnorm(100,0,1), "else"=rnorm(100,2,0.1))
foo.cor.df <- cor(foo.df)
结果矩阵中的列名是 "for." 和 "else.",后缀为句点。这有记录吗?除了清理新列名称之外,还有其他解决方案吗?
for
和 else
是 R 中的保留字,将它们用作数据帧中的名称是无效的。请参阅 ?data.frame
和 check.names
参数,它将您引导至 ?make.names
,其中包含:
Details:
A syntactically valid name consists of letters, numbers and the
dot or underline characters and starts with a letter or the dot
not followed by a number. Names such as ‘".2way"’ are not valid,
and neither are the reserved words.
注意最后一行。
已添加附加的 .
以使名称有效。