jeudi 21 décembre 2017

Case When LIKE equivalent in R

I am wanting to do similar to a case statement in r for a variable utilizing an ifelse statement. For example, lets say I have the following column vector 'Letter_Test' in a data frame that has:

Alpha - Test, Beta- Test, Zeta-Test, Alpha-Two, Beta-Two

I'd like to write a statement that says basically if data is like Alpha then 'Alpha', else return the column result.

In SQL that would be (CASE WHEN Letter_Test LIKE '%Alpha%' THEN Alpha else 'Letter-Test' end).

Aucun commentaire:

Enregistrer un commentaire