title: Transform Boolean Column to Numerical Column in Apache Spark (Scala) data frame with constraints?
body: <pre><code> val inputfile = sqlContext.read
          .format("com.databricks.spark.csv")
          .option("header", "true") 
          .option("inferSchema", "true") 
          .option("delimiter", "\t")
          .load("data")
   inputfile: org.apache.spark.sql.DataFrame = [a: string, b: bigint, c: boolean]
   val outputfile = inputfile.groupBy($"a",$"b").max($"c")
  </code></pre>
  
  <p>Above code fails because <code>c</code> is a boolean variable and aggregates cannot be applied to booleans. Is there a function in Spark that converts <code>true</code> value to <code>1</code> and <code>false</code> to <code>0</code> for the full column of Spark data frame.</p>
  
  <p>I tried the following (Source: <a href="https://stackoverflow.com/questions/29383107/how-to-change-column-types-in-spark-sqls-dataframe/33423959">How to change column types in Spark SQL&#39;s DataFrame?</a> )</p>
  
  <pre><code> val inputfile = sqlContext.read
          .format("com.databricks.spark.csv")
          .option("header", "true") 
          .option("inferSchema", "true") 
          .option("delimiter", "\t")
          .load("data")
   val tempfile =inputfile.select("a","b","c").withColumn("c",toInt(inputfile("c")))   
   val outputfile = tempfile.groupBy($"a",$"b").max($"c")
  </code></pre>
  
  <p>Following question: <a href="https://stackoverflow.com/questions/33354571/casting-a-new-derived-column-in-a-dataframe-from-boolean-to-integer">Casting a new derived column in a DataFrame from boolean to integer</a> answers for PySpark but I wanted a function specifically for Scala.</p>
  
  <p>Appreciate any kind of help.</p>