繁体   English   中英

是否有 R 方法可以保留数字并丢弃具有相同值的文本(例如 6 和位)

[英]Is there an R method that can keep numbers and discard text that are in the same value (e.g. 6 and a bit)

我有一个包含杂乱数据的示例数据框的任务。

问题之一是包含数字和文本的值,例如

Heights
10
8
12
6 but a bit bent at the top

因此,该列是一个因素。 我曾尝试使用 as.numeric(as.character(f)) 将数字+文本值转换为 NA。

如何在删除文本时保留数字 (6)(但顶部有点弯曲)?

不好了。 这是正则表达式:(

x$y= regmatches(x$y, gregexpr("\\d+|\\d+\\.\\d+", x$y)) %>%

其中: x = 数据框 y = 列名

暂无
暂无

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

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