Search code examples
rsubsetzeroleading-zero

Create a subset containing '0' as records


I have a dataframe whose one field contains different numbers. However, it also contains some 0/000/00000000. How can I identify in a given dataset all the values containing 0,00,000,0000,00000 and so on until 0000000000 and display all those records? Using OR logical operator for all the combinations seems tedious. Is there any other workaround?


Solution

  • Use regular expressions. I assume it is a character vector.

    grep("^0+$", df$col)