简体   繁体   English

使用gsub函数清除R中数据框中的列

[英]Use of gsub function to clean a column in a data frame in R

I have a column showing total assets of some people in Rs 3,94,24,827 ~ 3 Crore+ this format. 我有一列显示某些人的总资产,其格式为3,94,24,827卢比〜3千万卢比 I want this column to show only numeric data ie 39400000 for the above value and same for every row. 我希望此列仅显示数字数据,即上述值39400000,并且每行相同。 How to do this in R. 如何在R中执行此操作

What if you try something like 如果您尝试类似

text=“Rs 3,94,24,827 ~ 3 Crore+”
gsub(“\\D”,””,gsub(“,[2].+”,”00000”,text))
[1] “39400000”

To obtain the number alone; 单独获得号码;

gsub(“(~.*)|\\D”,””,text)
[1]”39424827”

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

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