0 votes
in Datenauswertung by s084918 (335 points)
reshown by s084918

Ich möchte in einer Variable meine NA in other umbenennen, da durch das Entfernen von NA sonst zu viele Fälle insgesamt gelöscht werden würden.

Bislang habe ich das über folgende Funktion probiert, allerdings bleiben die NA dann NA:

data$new<-recode(data$old, '"trust"="trust";"nottrust"="nottrust";"NA"="other"')

Wie kann ich NA sonst umbenennen?

Die Variable ist als Faktor angelegt.

1 Answer

0 votes
by SoSci Survey (304k points)
selected by s084918
 
Best answer

Es gibt sicher ein halbes Dutzend Pakete und Methoden, um diese Änderung vorzunehmen. Wenn Sie es mit den Hausmitteln von R ganz hausbacken machen möchten:

data$newVar = as.character(data$oldVar)
data$newVar[is.na(data$newVar)]  = "other"
data$newVar = as.factor(data$newVar)

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...