0

I have a dataframe emissions that looks like this (example):

CEDS_Sector                    Ammonia      Carbon Dioxide     ...
1A1a_Public Electricity         2528             NA
1A1b_Pet_refining               NA               NA
1A1c_Coke-ovens                 0.000           1467
...

CEDS_Sector is a factor, and all other columns are numeric. If there is an NA or 0 entry, I want that cell to become blank. If there is a > 0 value, I want that cell to have an "X" in it, to look like this"

CEDS_Sector                    Ammonia      Carbon Dioxide     ...
1A1a_Public Electricity           X             
1A1b_Pet_refining              
1A1c_Coke-ovens                                   X
...
Maridee Weber
  • 231
  • 1
  • 8

1 Answers1

2

You can do this with mutate_if():

library(dplyr) 

emissions %>% 
  mutate_if(is.numeric, function(x) ifelse(is.na(x) | x == 0, 
                                           "",
                                           "X"))
CzechInk
  • 443
  • 2
  • 13