writing a function in R that selects the a string based on the first instance of a letter and replaces the string
I have a data frame with several variables like this:
land_unit<-c("0.5ha", "hactares", "ha", "ha", "acre", "3ha", "lima", "limas", "acre", "cunny", "6 cunnies")
I want to write a function that will tidy this data for me as i have many variables in my data frame with a similar format. I would like the function to replace each element based on the first letter that appears in the string. For example if the first letter to appear in the string is "h" I want the whole string replaced by "ha", if "l" then "lima", if "a" then "acre" and if "c" then "kani".
I have searched widely on this but cannot find an answer, however I am aware that there must be a relatively simple solution. Perhaps using regex?
Any help would be greatly appreciated.