字母数字到r的数量增加
我在r中有一张iD列,例如:'1a','2a','1b','2b'等。
我想将它们转换为:1、2、3、4,,等等。
我感谢任何建议。 谢谢!
I have a table in R with a column of ID's like: '1A', '2A', '1B', '2B', etc.
I would like to convert them to numbers such as: 1, 2, 3, 4, etc.
I would appreciate any suggestion.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
另一种方法是转换为一个因素,然后转换为数字。这样就没有顺序顺序的假设。
Another way is to convert to a factor, and then to numbers. that way there is no assumptions of sequential order.
假设ID是按顺序
排序
的使用
row_number
assuming that the IDs are in sequential order replace the
IDs
vector with a sequence of numbers starting at 1 and ending at the length of the data framealternatively:
The
tidyverse
solution would be to userow_number