To regex all numbers in R, you can use the gsub()
function and a regular expression pattern to replace all non-numeric characters with an empty string. Here's an example:
main.r265 chars9 lines
Output:
main.r42 chars2 lines
This will remove all non-numeric characters from the strings
vector, leaving only the numeric strings. The regular expression pattern "[^[:digit:]]"
matches any character that is not a digit, and the gsub()
function replaces each of these characters with an empty string.
gistlibby LogSnag