How to remove only "actual numbers" from a string of characters in R

wen

I have a string of numbers and characters

c2 = "list of 2nd C2 H2O 1 12 123"

I need to get rid of all digits that are actual numbers, i.e. 1, 12, 123, but not the ones that are part of a character set, i.e. 2nd, C2, H2O.

So far, the best solution I have come up with is this

gsub("? [[:digit:]]*", " ", c2)
"list of nd C2 H2O   "

It successfully gets rid of 1 12 123, while retaining C2 H2O. However, I lost 2 in 2nd.

I am at my wits end.

Thanks!

G. Grothendieck

Try this:

> gsub("\\b\\d+\\b", "", c2)
[1] "list of 2nd C2 H2O   "

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how to remove characters only from the end of a string?

From Dev

how to remove all characters from string and leave numbers only in dataframe?

From Dev

how to remove special characters and number patterns from a string in R

From Dev

R remove only "[" "]" from string

From Dev

Remove characters from a string BEFORE a word (in R)

From Dev

How to remove duplicated characters from string in Bash?

From Dev

How to remove escape characters from a JSON String

From Dev

How to remove certain characters from a string? [Python]

From Dev

How to remove all '\' characters from a string in java

From Dev

How to remove characters from a matching string?

From Dev

How to remove characters from string in iOS?

From Dev

how to remove digits or numeric characters from the string

From Dev

how to remove unwanted characters from string in PHP

From Dev

How to remove characters from the end of the string?

From Dev

How to remove duplicated characters from string in Bash?

From Dev

How to remove characters and special notations from string

From Dev

How to remove escape characters from Json string?

From Dev

how to remove alternate characters from a php string

From Dev

How can we remove a ':' characters from a string?

From Dev

How to remove sequence of characters from string

From Java

How to remove only symbols from string in dart

From Dev

How to remove only certain substrings from a string?

From Dev

How to remove only some spaces from string?

From Dev

How to remove characters in r

From Dev

How to retrieve certain characters from a string in R?

From Dev

remove characters from a python string

From Dev

Remove characters from String in Haskell

From Dev

Remove specific characters from a string

From Dev

Remove characters from query string

Related Related

  1. 1

    how to remove characters only from the end of a string?

  2. 2

    how to remove all characters from string and leave numbers only in dataframe?

  3. 3

    how to remove special characters and number patterns from a string in R

  4. 4

    R remove only "[" "]" from string

  5. 5

    Remove characters from a string BEFORE a word (in R)

  6. 6

    How to remove duplicated characters from string in Bash?

  7. 7

    How to remove escape characters from a JSON String

  8. 8

    How to remove certain characters from a string? [Python]

  9. 9

    How to remove all '\' characters from a string in java

  10. 10

    How to remove characters from a matching string?

  11. 11

    How to remove characters from string in iOS?

  12. 12

    how to remove digits or numeric characters from the string

  13. 13

    how to remove unwanted characters from string in PHP

  14. 14

    How to remove characters from the end of the string?

  15. 15

    How to remove duplicated characters from string in Bash?

  16. 16

    How to remove characters and special notations from string

  17. 17

    How to remove escape characters from Json string?

  18. 18

    how to remove alternate characters from a php string

  19. 19

    How can we remove a ':' characters from a string?

  20. 20

    How to remove sequence of characters from string

  21. 21

    How to remove only symbols from string in dart

  22. 22

    How to remove only certain substrings from a string?

  23. 23

    How to remove only some spaces from string?

  24. 24

    How to remove characters in r

  25. 25

    How to retrieve certain characters from a string in R?

  26. 26

    remove characters from a python string

  27. 27

    Remove characters from String in Haskell

  28. 28

    Remove specific characters from a string

  29. 29

    Remove characters from query string

HotTag

Archive