Filtering names with letters only

Hi,
I have this simple df:

df <- data.frame(
  stringsAsFactors = FALSE,
            Market = c("00", "01", "02", "03", "77", "99", "SI", "TR", "UA"),
             value = c(2219, 1091, 933, 910, 1100, 2286, 9165, 299, 504)
)

Market names containing letters are valid, containing numbers are invalid. I would like to either:

  1. Create a new variable (Vali.Markets) where correct names are flagged (for example as 1 therefore invalid as 0)
  2. Subset my df which would contain only valid records straight away without creating a filtering variable

Is this possible?

df <- data.frame(
  stringsAsFactors = FALSE,
  Market = c("00", "01", "02", "03", "77", "99", "SI", "TR", "UA"),
  value = c(2219, 1091, 933, 910, 1100, 2286, 9165, 299, 504)
)

library(tidyverse)

df %>% filter(is.na(parse_number(Market)))
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.