I need help using the ifelse
function in r
.
My data is titled infringements. So far, I have successfully created a new variable from an existing variable with this code:
infringements$closure <- ifelse(infringements$Decision_type == "Closing of the case", yes = TRUE, no = FALSE)
However, now, I need to do the same thing, but instead of only one type of decision such as "Closing of the case", I have multiple decision types that I would like to make into one variable. For instance, my code looks like this:
infringements$let <- factor(ifelse(infringements$Decision_type ==
c("Formal notice Art. 258 TFEU" "Formal notice Art. 106 TFEU" "Formal notice Art. 258 TFEU + Press release" "Formal notice Art. 260 TFEU")
yes = TRUE, no = FALSE))
However, this code does not work and only returns FALSE statements.
Also, instead of labelling my new variables as either TRUE or FALSE, I would like to label them yes (when TRUE) and no (when FALSE)
Any help would be very appreciated. Thank you!
Aucun commentaire:
Enregistrer un commentaire