How can I address a partial match in a data frame? Lets say this is my df df
V1 V2 V3 V4
1 ABC 1.2 4.3 A
2 CFS 2.3 1.7 A
3 dgf 1.3 4.4 A
and I want to add a column V5 containing a number 111 only if the value in V1 contains a "f" in the name and a number 222 only if the value in V1 contains a "gf". Will I get problems since several values contain an "f" - or does the order I ender the commands will take care of it?
I tried something like:
df$V5<- ifelse(df$V1 = c("*f","*gf"),c=(111,222) )
but it does not work.
Main problem is how can I tell R to look for "partial match"?
Thanks a million for your help!