Skip to content

Commit ebf250b

Browse files
committed
feat: add tidypolars for replacing with an expression
1 parent 0fc34cf commit ebf250b

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

book/content/data_manipulation/_missing_values.qmd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,17 @@ mydfNA$
269269
pl$col("colB")$fill_null(pl$col("colA"))$name$suffix("_corrected")
270270
)
271271
```
272+
## tidypolars
273+
274+
```{r}
275+
#| label: replace-missing-values-expression-tidypolars
276+
# Replace missing values with the mean of the non-null values for that column
277+
mydfNA %>%
278+
mutate(colB_corrected = ifelse(is.na(colB), colA, colB))
279+
# Replace missing values with the values from another column
280+
mydfNA %>%
281+
mutate(colB_corrected = ifelse(is.na(colB), colA, colB))
282+
```
272283

273284
## R base
274285

0 commit comments

Comments
 (0)