Adding column based on other column

Hey @livjos! You might be interested in some of the functions in the dplyr package:

  • dplyr::recode() can directly translate values of a column (eg. "D" becomes "Diseased") (oops, I thought you had H or D in a separate column), and
  • dplyr::case_when() can create values for a column based on conditions in one or more other columns.

If you have a peak at the documentation links for those functions, they'll show you some great examples of what you want to do. In this case, you might want to use case_when() with the base endsWith() function, which will return TRUE or FALSE depending on whether each row ends with the supplied suffix.

If you get stuck using them, come back with a reproducible example (reprex) and we can help you out more :slight_smile:

1 Like