简体   繁体   English

当列名是数字时,如何使用收集函数(tidyr包)?

[英]How to use gather function (tidyr package) when column names are numeric?

Is there any way I can use the gather function in the tidyr package to gather columns whose names are numeric characters? 有没有什么办法可以使用tidyr包中的gather函数来收集名称为数字字符的列? For example: 例如:

0           1            1.5
0.072008549 0.0722986133 0.0724443032
0.016977539 0.0171147309 0.0171839512
0.007328922 0.0074180263 0.0074631892
0.002660683 0.0027039452 0.0027259732
0.000406033 0.0004143108 0.0004185449

When you have numeric names, make sure to escape them using backticks "`". 如果你有数字名称,请确保使用反引号“`”来转义它们。 For example gather(d, key, value, `0`) 例如, gather(d, key, value, `0`)

除了使用反引号,您还可以按编号引用列:

gather(df, key, value, 2:3)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM