Suppose you have a table of data:
df<-tibble(person = c("Alice", "Bob", "Mary"),
colour = c("Red", "Green", "Blue"),
city = c("London", "Paris", "New York"))
# A tibble: 3 x 3
person colour city
<chr> <chr> <chr>
1 Alice Red London
2 Bob Green Paris
3 Mary Blue New York
And a second table which contains the field names and the maximum string length of each field:
len<-tibble(field_name = c("person", "colour", "city"),
field_length = c(12, 4, 6))
# A tibble: 3 x 2
field_name field_length
<chr> <dbl>
1 person 12
2 colour 4
3 city 6
How can I check, for each field in len, whether a string in df is less than or equal to len$field_length, returning rows which fail the test?
As an example:
Output Row 1 in df would pass because:
- 'Alice' <= 12 characters long,
- 'Red' is <= 4 characters long and
- 'London' is <= 6 characters long.
However,
- Row 2 would fail because:
- 'Green' > 4 characters long and
- Row 3 would fail because:
- 'New York' > 6 characters long.
Thus the returned data frame should only display Rows 2 and Row 3 of the original df.