title: How To Apply Multiple Conditions on Case-Otherwise Statement Using Spark Dataframe API
body: <p>I am trying to add a new column to an existing data frame using the <code>withColumn</code> statement in <code>Spark Dataframe API</code>. The below code works but I was wondering if there's a way that I can select more than one group. Let's say Group 1, 2, 3, 4 instead of only Group 1. I think I may be able to write <code>when</code> statement four times. I have seen people do that in some posts. However, in <code>R</code>, there is a <code>%in%</code> operator that can specify if a variable contains values in a vector, but I don't know if there's such thing in Spark. I checked on the Spark API documentation but most of the functions don't contain any examples.  </p>
  
  <pre><code># R Sample Code:
   library(dplyr)
   df1 &lt;- df %&gt;% mutate( Selected_Group = (Group %in% 1:4))
  </code></pre>
  
  <p>Spark Dataframe Sample Code That Selects Group 1:  </p>
  
  <pre><code> val df1 = df.withColumn("Selected_Group", when($"Group" === 1, 1).otherwise(0))
  </code></pre>
  
  <blockquote>
    <p>Data</p>
    
    <p>ID, Group<br>
     1,  0<br>
     2,  1<br>
     3,  2<br>
     .   .<br>
     .   .<br>
    100, 99</p>
  </blockquote>