I'm a new to R and need help with the following.
| Have | Need |
|---|---|
| Male_18_24_pn | 18_24 |
| Male_25_39_pn | 25_39 |
| Male_40_64_pn | 40_64 |
| Male_65_84_pn | 65_84 |
| Male_85_plus_pn | 85_plus |
| Female_18_24_pn | 18_24 |
I need to create the "Need" column using the "Have" column, wondering how I can achieve this in R. As a initial effort, I tried the following code to test but got warning message and every cell of "Need" populated with "18_24":
if (str_detect(pe_1P_new$Have,"18_24")) {pe_1P_new$Need= "18_24"}
Warning message:
In if (str_detect(pe_1P_new$Have, "18_24")) { :
the condition has length > 1 and only the first element will be used
Your help is greatly appreciated. Thanks in advance!