Hello,
the following code is extracted from a function where roughly 150 variables of
a large data set are transformed using data.table.
The variable "membre" was coming out with one missing value, in trying to
understand why, I extracted the code from the function, added a few "cat"
statements and ran it directly in the terminal.
ttt.test.sima[, ":=" (membre = {##
+ cat(" Processing: membre", sep = "\n")
+ ttt <- membre
+ cat(paste(" Class ttt = ", class(ttt), sep = ""), sep = "\n")
+ cat(paste(" Length ttt = ", length(ttt), sep = ""), sep = "\n")
+ cat(paste(" sum(ttt == 0) = ", sum(ttt == "0"), sep = ""), sep = "\n")
+ ttt[ttt == "0"] <- "O" ## A few capital "O" are coded as zero "0".
+ cat(paste(" sum(ttt == 0) = ", sum(ttt == "0"), sep = ""), sep = "\n")
+ ttt <- ifelse(PROV != " QC", " OAO",
+ ifelse(membre == "", " Ma ", membre))
+ cat(paste(" sum(ttt == 0) = ", sum(ttt == "0"), sep = ""), sep = "\n")
+ merge.levels(factor(ttt, levels = c("O", "N", " Ma ", " OAO"),
+ labels = c(" Oui", " Non", " Ma ", " OAO")),
+ k = list(" Oui" = c(" Oui", " OAO")))})]
Processing: membre
Class ttt = character
Length ttt = 4750880
sum(ttt == 0) = 2
sum(ttt == 0) = 0
sum(ttt == 0) = 1
I don't understand why after the « ifelse» statement the temporary variable «
ttt» is back with a single « 0 (zero)» in it, resulting of course in the
missing value of the factor created from it.
Thanks for your support,
Gérald
[cid:[email protected]]
Gerald Jean, M. Sc. en statistiques
Conseiller senior en statistiques
Actuariat corporatif,
Modélisation et Recherche
Assurance de dommages
Mouvement Desjardins
Lévis (siège social)
418 835-4900,
poste 5527639
1 877 835-4900,
poste 5527639
Télécopieur : 418 835-6657
Faites bonne impression et imprimez seulement au besoin!
Ce courriel est confidentiel, peut être protégé par le secret professionnel et
est adressé exclusivement au destinataire. Il est strictement interdit à toute
autre personne de diffuser, distribuer ou reproduire ce message. Si vous l'avez
reçu par erreur, veuillez immédiatement le détruire et aviser l'expéditeur.
Merci.
_______________________________________________
datatable-help mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help