I have a dataset that I am converting from long to wide format. My original dataset contains countries of occurrence for each species ("code") as one of the columns. I have created new columns for all country codes (e.g., "FI", "NO"), and I now need to translate the data in "code" to these columns (e.g., for df$FI, if df$Name == "FI" then YES, otherwise NA). Is there a way of automating this across all of these new columns (so that a YES value will be returned if the value in df$Name is equivalent to the column title, otherwise an NA value will be returned), or do I have to do this manually for each new column created? Thanks.
Name code
1 ABC FI
2 ABC NO
3 ABC RU
4 ABC SE
5 BCD IT
6 BCD RO