Here you are doing a substraction, for the first row 82280 - NA - NA. This is the same as asking R "I had $82280, then I spent some money, then I spent more money, how much do I have left?" the answer is we can't know (i.e. NA).
What you want is to use if_else() and is.na(). Here is code for using the value of NP when NP_C OR NP_T are NA.
df <- data.frame(
stringsAsFactors = FALSE,
Date = c("2015/01/01",
"2015/01/01","2015/01/01",
"2015/01/01","2015/02/01"),
Country = c("Brazil",
"Canada","Mexico","USA","Brazil"),
M = c(510875,95736,
319243,1205822.64843412,457566),
NP = c(82280,19147.2,
180710,217251,74068),
NP_C = c(12345, 12345, NA, NA, NA),
NP_T = c(54321, NA, 54321, NA, NA)
)
# Calculating P and NP_O
df %>%
mutate("P" = M - `NP`)%>%
mutate("NP_O" = if_else(is.na(NP_C) | is.na(NP_T), NP, NP - NP_C - NP_T))
Note that I changed some values in NP_C and NP_T to better illustrate.
if_else() has 3 arguments, the condition, what to do if true, and what to do if false. You can build the condition with | (or) and & (and). If any of NP_C or NP_T is NA, then you return NP. You weren't clear on what you wanted to do if they are not NA, i.e. the condition is false, so here I just did teh subtraction.