NAs into 0 in mutate (dplyr)

In my dataset, I have this variable called Freq that has values for the individuals that had a recording and is NA for the rest. I want to turn these NAs to zeros, as it serves the purpose of my analysis.

I tried:
poisson_data3 <- poisson_data2 %>% mutate(Freq2 = case_when( 0,
! Freq))

where i create a new variable called Freq2 which uses the values from Freq (when they are there) and is 0 (when there are no values).

However this returns an error in R.

Any suggestions on how this could be solved or if any other command would be better?

Thanks in advance

Should work. What is the error message you're getting?

Alternatively, there's poisson_data2 %>% mutate(Freq2 = replace_na(Freq, 0))

1 Like

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.