数据框列命名
我正在创建一个像这样的简单数据框:
qcCtrl <- data.frame("2D6"="DNS00012345", "3A4"="DNS000013579")
我的理解是列名称应该是“2D6”和“3A4”,但它们实际上是“X2D6”和“X3A4”。为什么要添加 X 以及如何停止这种情况?
I am creating a simple data frame like this:
qcCtrl <- data.frame("2D6"="DNS00012345", "3A4"="DNS000013579")
My understanding is that the column names should be "2D6" and "3A4", but they are actually "X2D6" and "X3A4". Why are the X's being added and how do I make that stop?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不建议使用以数字开头的列名称,但如果您坚持,请使用
data.frame
的check.names=FALSE
参数:我谨慎的原因之一与此相反,
$
运算符的使用变得更加棘手。例如,以下内容会失败并出现错误:要解决此问题,无论何时使用列名,都必须将其括在反引号中:
I do not recommend working with column names starting with numbers, but if you insist, use the
check.names=FALSE
argument ofdata.frame
:One of the reasons I caution against this, is that the
$
operator becomes more tricky to work with. For example, the following fails with an error:To get round this, you have to enclose your column name in back-ticks whenever you work with it:
添加 X 是因为 R 不喜欢将数字作为列名称的第一个字符。要关闭此功能,请使用
as.character()
告诉 R 数据框的列名称是字符向量。The X is being added because R does not like having a number as the first character of a column name. To turn this off, use
as.character()
to tell R that the column name of your data frame is a character vector.