我有一个包含字母数字字符的字符向量d
d <- c("012309 template", "separate 00340", "00045", "890 098", "3405 garage", "matter00908")
d
[1] "012309 template" "separate 00340" "00045" "890 098" "3405 garage" "matter00908"
如何从R中所有数字中删除前导零?as.numeric
仅会移除数字或整数向量中的所有前导零。我尝试了使用regex
的gsub
,但无法得到期望的结果。
期望的输出如下所示:
out <- c("12309 template", "seperate 340", "45", "890 98", "3405 garage", "matter908")
out
[1] "12309 template" "seperate 340" "45" "890 98" "3405 garage" "matter908"