title: Calculate mean and max value with VectorAssembler
body: <p>I'm working with a data frame, something like:</p>
  
  <pre><code>from pyspark.mllib.linalg import Vectors
  from pyspark.ml.feature import VectorAssembler
  
  
  from pyspark.sql.types import *
  
  schema = StructType([
      StructField("ClientId", IntegerType(), True),
      StructField("m_ant21", IntegerType(), True),
      StructField("m_ant22", IntegerType(), True),
      StructField("m_ant23", IntegerType(), True),
      StructField("m_ant24", IntegerType(), True)
  ])
  
  df = sqlContext.createDataFrame(
                               data=[(0, 5, 5, 4, 0),
                                     (1, 23, 13, 17, 99),
                                     (2, 0, 0, 0, 1),
                                     (3, 0, 4, 1, 0),
                                     (4, 2, 1, 30, 10),
                                     (5, 0, 0, 0, 0)],
                                     schema=schema)
  </code></pre>
  
  <p>I need to calculate the mean value an max value per row and using the columns "m_ant21", "m_ant22", "m_ant23", "m_ant24".</p>
  
  <p>I'm trying using vectorAssembler:</p>
  
  <pre><code>assembler = VectorAssembler(
      inputCols=["m_ant21", "m_ant22", "m_ant23","m_ant24"],
      outputCol="muestra")
  output = assembler.transform(df)
  output.show()
  </code></pre>
  
  <p>now, I create a function to make the mean, but the input variable is a "DenseVector" called "dv":</p>
  
  <pre><code>   dv = output.collect()[0].asDict()['muestra']
  
  def mi_media( dv ) :
      return float( sum( dv ) / dv.size  ) 
  
  
  udf_media  = udf( mi_media, DoubleType() )
  output1 = output.withColumn( "mediaVec",  udf_media ( output.muestra ) )
  output1.show()
  </code></pre>
  
  <p>and the same to the max value:</p>
  
  <pre><code>def mi_Max( dv ) :
          return float(max( dv )  )   
  udf_max  = udf( mi_Max, DoubleType() )
  output2 = output.withColumn( "maxVec",  udf_max ( output.muestra ) )
  output2.show()
  </code></pre>
  
  <p>The problem is the error in output1.show() and output2.show(). Just It's not working and I dont know what happends with the code.
  What am i doing wrong?
  Please help me.</p>