I'm using dplyr and I want to select all the columns on the table but return only the rows where one specific column ends with '006'.
select(sample_id, ends_with("006"), everything())
The code above doesn't work. When I run it, it returns all rows (or more than I need -- it's a huge dataset).
I've tried using:
filter(sample_id == ends_with('006'))
but ends_with() needs to be used within a select function.
Use
str_endsfrom packagestringr:By default the pattern is a regular expression. You can match a fixed string with:
Of course it's also possible to use a more general regular expression. It's useful if you have a more complex pattern to check, but it also works here:
See also: Detect the presence or absence of a pattern at the beginning or end of a string.