using the following dataset
structure(list(...1 = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12), V1 = c("overstress", "flicker", "lotteri", "life",
"charg", "capac", "health", "drain", "degrad", "protector", "bright",
"use", "overstress", "flicker", "lotteri", "life", "charg", "capac",
"health", "drain", "degrad", "protector", "bright", "use", "overstress",
"flicker", "lotteri", "life", "charg", "capac", "health", "drain",
"degrad", "protector", "bright", "use"), term = c("corr1", "corr1",
"corr1", "corr1", "corr1", "corr1", "corr1", "corr1", "corr1",
"corr1", "corr1", "corr1", "corr2", "corr2", "corr2", "corr2",
"corr2", "corr2", "corr2", "corr2", "corr2", "corr2", "corr2",
"corr2", "corr3", "corr3", "corr3", "corr3", "corr3", "corr3",
"corr3", "corr3", "corr3", "corr3", "corr3", "corr3"), correlation = c(0.5,
0.43, 0.42, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.53,
0.29, 0.25, 0.25, 0.23, 0.2, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, 0.45, 0.16, 0.15)), row.names = c(NA, -36L), class = c("tbl_df",
"tbl", "data.frame"))
I am looking to change if the word is corr1, corr2 or corr3, to toil1,toil2 or toil3. I tried the following code, but only receive the following error term:
three_terms_corrs_gathered$term <- if
(three_terms_corrs_gathered$term == "corr1"){toil1} else if
(three_terms_corrs_gathered$term == "corr2"){toil2} else
{toil3}
Warning message:
In if (three_terms_corrs_gathered$term == "corr1") { : the condition
has length > 1 and only the first element will be used. So it only
changes to the first condition. What am I doing wrong?
question from:
https://stackoverflow.com/questions/65906378/using-an-if-function-how-do-i-change-string-of-text-in-dataframe-to-another-str