mardi 26 novembre 2019

Whats the "meaning" in R of this code-chunk?

I know there are tons of ressources out there. And I'd be superhappy to receive some indications of good ones, as it is quite difficult for a beginner to really know what's a good ressource. My question here is what's the actualy sense of the . and the ~ in the following code. I know that they encode all -1s and 99s as NA. But why this complicated looking syntax?

mutate_all(df, list(~ifelse(. %in% c(-1, 99), NA, .)

So there is the data.frame df which has several columns. In all the encoding for NAs is either -1 or 99. I think dplyr also has a na_if-function. And wouldn't that be easier to use here?

Aucun commentaire:

Enregistrer un commentaire