简体   繁体   English

如何从向量中的某些元素中删除某些特殊字符?

[英]How to remove certain special character occurrences from some elements in a vector?

I have a vector filled with some numbers that I read from a .csv file, but some of those numbers are preceded by a * ,that is, 我有一个向量,里面充满了一些我从.csv文件读取的数字,但是其中一些数字前面带有*,即,

12 34 *89 *45 34

I want to remove the * from these elements while retaining their types, that is 我想从这些元素中删除*并保留其类型,即

12 34 89 45 34

How do I do this? 我该怎么做呢?

Try: 尝试:

as.integer(stringi::stri_extract_all(x, regex = "[[:digit:]]+", simplify = TRUE))

Which gives: 这使:

#[1] 12 34 89 45 34

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

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