I have a numerical column with NAs, negative, positive, and 0 values. What I want is the following:
Data:
df <- data.frame (a = c(12,-34,NA,-23,5,0,NA))
Expected outcome:
a
1 +12
2 -34
3 NA
4 -23
5 +5
6 0
7 NA
Another possible solution, based on formatC
:
gsub("NA", NA, formatC(df$a, flag = "+0", zero.print = T))
#> [1] "+12" "-34" NA "-23" "+5" "0" NA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With