Why do these 2 ways of making changes to a base produce different bases when it should be the same result?
This way I put all the changes in the same mutate
df1<-
df%>%
mutate(contactos_prom= contactos_sistema/10,
contactos_prom1= case_when(between(contactos_prom, 0, 7) ~ "Hasta 7",
between(contactos_prom, 7.1, max(aticamama$contactos_prom)) ~ "7,1 y mas"),
contactos_prom2= case_when(between(contactos_prom, 0, 3.5) ~ "Hasta 3,5",
between(contactos_prom, 3.51, 7) ~ "3,51 a 7",
between(contactos_prom, 7.1, max(aticamama$contactos_prom)) ~ "Mas de 7"))
Warning message:
There were 4 warnings in `mutate()`.
The first warning was:
ℹ In argument: `contactos_prom1 = case_when(...)`.
Caused by warning:
! Unknown or uninitialised column: `contactos_prom`.
ℹ Run dplyr::last_dplyr_warnings() to see the 3 remaining warnings.
In this way I put the changes in mutate separately and no warning appears
df<-
df%>%
mutate(contactos_prom= contactos_sistema/10)
df<-
df%>%
mutate(contactos_prom1= case_when(between(contactos_prom, 0, 7) ~ "Hasta 7",
between(contactos_prom, 7.1, max(aticamama$contactos_prom)) ~ "7,1 y mas"),
contactos_prom2= case_when(between(contactos_prom, 0, 3.5) ~ "Hasta 3,5",
between(contactos_prom, 3.51, 7) ~ "3,51 a 7",
between(contactos_prom, 7.1, max(aticamama$contactos_prom)) ~ "Mas de 7"))
If I check there are not the same df, why?
all.equal(df, df1)
[1] "Component “contactos_prom1”: 'is.NA' value mismatch: 132 in current 0 in target"
[2] "Component “contactos_prom2”: 'is.NA' value mismatch: 132 in current 0 in target"