Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

complete fill = 0 for all, not just specific columns

Reading docs here for complete()

fill:
A named list that for each variable supplies a single value to use
instead of NA for missing combinations.

Example priovided:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

df %>%
  complete(
    group,
    nesting(item_id, item_name),
    fill = list(value1 = 0, value2 = 99)

My question is, can I tell complete to fill all with 0? Tried just fill = 0 which returned an error. I have more than 100 cols!

>Solution :

in the case you want to fill all columns,

library(dplyr)
library(tidyr)

df %>%
  complete(
    group,
    nesting(item_id, item_name),
    fill = across(everything(), ~0)
  )
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading