Tiptop
Tiptop

Reputation: 623

Dividing columns containing NA

I'm trying to divide two columns both containing NA's, but can't make it work.

I've tried this:

df%>%
mutate(c_n = c / n, na.rm = TRUE)

All help is much appreciated!

Upvotes: 0

Views: 1781

Answers (2)

AnilGoyal
AnilGoyal

Reputation: 26218

Use simply

df%>%
mutate(c_n = c / n)

NAs will automatically be left as they are

Upvotes: 2

ThomasIsCoding
ThomasIsCoding

Reputation: 101064

If you would like to keep NAs, you can try

df %>%
  mutate(c_n = C / N)

Upvotes: 1

Related Questions