This is very simple yet I cannot get it 100% right!
I have column of data that looks like this:
"424343 Amsterdam center"
"343423 London 42 ......"
"3434 Prague ........."
"343345 Bratislava ...."
"! last entry ..... 25.08.2014..."
"Berlin"
...
...
I would like to replace all rows starting with letter with empty string ""
I have tried:
dataframe$column[grepl("(^[A-Z]+).*",dataframe$column)] <- ""
I'm still getting the rows like these .... "! last entry ..... 25.08.2014..."
Desired output:
"424343 Amsterdam center"
"343423 London 42 ......"
"3434 Prague ........."
"343345 Bratislava ...."
""
""
...
...
You can look just for strings starting with at least one number and take all non matching results (using !
), e.g.:
!grepl("^[[:digit:]]+", text)
In your example:
dataframe$column[!grepl("^[[:digit:]]+",dataframe$column)] <- ""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With