read.table
系列(read.table
、read.csv
、read.delim
等) 的参数 check.names
具有以下解释:
logical. If
TRUE
then the names of the variables in the data frame are checked to ensure that they are syntactically valid variable names. If necessary they are adjusted (bymake.names
) so that they are, and also to ensure that there are no duplicates.
假设我加载了一个包含语法无效的列名的数据框。除了必须使用 `
字符按名称访问特定列之外,还有其他后果吗?
最佳答案
查看 help(make.names)
以了解它在做什么以及为什么。
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.
The definition of a letter depends on the current locale, but only ASCII digits are considered to be digits.
The character "X" is prepended if necessary. All invalid characters are translated to ".". A missing value is translated to "NA". Names which match R keywords have a dot appended to them. Duplicated values are altered by make.unique.
最让你困惑的是空白列名(df$``
给出错误)和重复的列名(df$val
将返回第一个仅val
列结果)。
关于r - 语法无效名称的后果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46225103/