How to take out na rows in a function ?

I'm using browser to debug and I noticed that one of my data sets has a row that is just NA. The error I'm getting is caused by 'across ()' and spits out 'Problem while computing column 'Property Count'. I'm assuming that's because of an NA row in between the df set, hence why I want to delete the N/A row.

The difficulty is that it is a combined set. I want to include something like na.omit in the code but I'm not sure how to structure it.

Edit: Here is an example of what the combined set looks like:

df = data.frame(
  a = c(4,NA,3),
  b = c(1,NA,3),
  c = c(2,NA,4),
  d = c(2,NA,1)
)

This is the actual code

total_stats = stats_combined %>% 
    rename(`Net Absorption` = `Net Absorption QTD - Total`, 
           `Net Absorption YTD` = `Net Absorption YTD - Total`,
           `Construction Deliveries` = `Construction Deliveries QTD`) %>% 
    filter(Submarket %in% submarket_order) %>% 
    mutate(Submarket = factor(Submarket, levels = submarket_order, ordered = T)) %>% 
    arrange(Submarket) %>% 
    # glimpse()
    mutate(across(c(`Direct Vacancy Rate`, `Overall Vacancy Rate`, `Overall Availability Rate`), scales::percent, accuracy = .1),
           across(any_of(sum_vars), 
                  scales::dollar, accuracy = 1, style_negative="parens", prefix=""),
           across(any_of(c("Full Service Gross Asking Rate", "Lease Rate")),
                  scales::dollar)) %>%
    select(Submarket, all_of(stat_order))
  market_stats_table(total_stats, 
                     cell_width = if_else(property_type == "Office", 1.05, .9), 
                     cell_height = if_else(property_type == "Office", .33, .27),
                     submarket_order,
                     totals)

How can I include something like na.omit to avoid getting this error :

Error in $<-.data.frame(*tmp*, "call_text", value = c("global key_market_stats(...)", :
replacement has 17 rows, data has 16

I would substitute a string for NA at the very beginning. Something like "N/A", which will prevent you from getting the kind of errors R spits out when dealing with NAs. This can be done with the following code.

df[is.na(df)] <- "N/A"

Thanks for responding, I had figured out how to get rid of the "N/A" a while back but that doesn't seem to be the root cause of my bug. Was able to fix it by tweaking my !missing function.
Running traceback it looks like it starts with the across function when I begin 'mutate'. As this is a different issue I will be closing this thread, thank you for the response.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.