Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206260

What's the easiest way for the multiple if-else conditions?

$
0
0

I have a data set something like this:

df_1 <- tribble(
  ~A,   ~B,  ~C,  
  10,   10,  NA,        
  NA,   34,  15,       
  40,   23,  NA,
   4,   12,  18,
)

Now, I just want to compare A, B, C for each row, and add a new column that shows us the minimum number. Let's see how desired data looks like:

df_2 <- tribble(
  ~A,  ~B,  ~C,  ~Winner,
  10,  10,  NA,  "Same",     
  NA,  34,  15,  "C",     
  40,  23,  NA,  "B",   
   4,  12,  18,  "A",
)

There are four outputs: Same, A-Win, B-Win, C-Win.

How would you code to get this result?

Thanks in advance.


Viewing all articles
Browse latest Browse all 206260

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>