Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove just strings from the entries in my first column of data frame

I have strings and numbers in my first column of a data frame:

rn

AT457

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

X5377

X3477

I want to remove just the strings and keep the numbers from each entry in the column called rn.

Any help is appreciated.

>Solution :

Use a regular expression to do this.

For example, with R :

## Sample data :
df=data.frame(rn=c("AT457","X5377","X3477"))

## Replace the letters with *nothing* ('\D' is used to identify non-digit characters)
df$rn_strip=gsub('\\D',"",df$rn)

## Output :

     rn rn_strip
1 AT457      457
2 X5377     5377
3 X3477     3477
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading