mardi 27 octobre 2020

Why does the column get not saved in an ifelse Function in R?

I have a simple ifelse line but the results are not saved. Why is this? The line itself works. But the results are not saved in the dataframe.

x<-Model$F_Q06c

ifelse(is.numeric(x), print("isnumeric"),ifelse(is.factor(x),"x" <-as.numeric(levels(x))[x],print("else")) )
"x" <-as.numeric(levels(x))[x]
str(x)
str(Model)

the value for x in "x" <-as.numeric(levels(x)) does not get saved. Why is that?

The background is that I have a model with a lot of factors and want to format them automatically.

Aucun commentaire:

Enregistrer un commentaire