从多种不同格式创建标准化数据表条目
我有一个包含多个字段的数据框。这些字段之一是“样本”,由于输入多种多样,我的样本使用多种格式命名。以下是一些示例:
"12" "250" "1248" "1_100111" "16_100111" "125_081811" "1249_100111"
上面的示例代表了大多数示例。我想将所有样本更改为 4 位数字格式,以便可以轻松对它们进行排序。上述示例的最终结果将是:
"0012" "0250" "1248" "0001" "0016" "0125" "1249"
因此,在某些情况下必须添加零,而在其他情况下必须删除日期标记。 非常重要的是,更改是在数据框的上下文中进行的,并以相同的格式返回。
I have a data frame that contains a number of fields. One of these fields is "Sample" and due to a variety of inputs my samples are named using a variety of formats. Here are some examples:
"12" "250" "1248" "1_100111" "16_100111" "125_081811" "1249_100111"
The above examples represent the majority of the samples. I would like to change all of the samples to a 4 digit format so they can be easily sorted. The final result of the above examples would be:
"0012" "0250" "1248" "0001" "0016" "0125" "1249"
Thus, in some cases zeros must be added and in other cases, the date marker must be cut off.
It is very important that the changes are made within the context of a data frame and returned in the same format.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
干得好:
Here you go: