Skip to content

Instantly share code, notes, and snippets.

@mhweber
Created September 16, 2015 15:10
Show Gist options
  • Save mhweber/07cf6548b7fb0ee26b68 to your computer and use it in GitHub Desktop.
Save mhweber/07cf6548b7fb0ee26b68 to your computer and use it in GitHub Desktop.
A reminder snippet on how to recode a data frame variable based on pattern matching another variable in the same data frame
x = c("AA","BB","A:B", "CC","C:A")
df = data.frame("ID" = x)
df
df$colons[grep(":", df$ID)] ='yes'
df$colons[is.na(df$colons)] ='no'
df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment