title: Changing column data type to factor with sparklyr
body: <p>I am pretty new to Spark and am currently using it using the R API through sparkly package. I created a Spark data frame from hive query. The data types are not specified correctly in the source table and I'm trying to reset the data type by leveraging the functions from <code>dplyr</code> package. Below is the code I tried:</p>
  
  <pre><code>prod_dev &lt;- sdf_load_table(...)
  num_var &lt;-  c("var1", "var2"....)
  cat_var &lt;-  c("var_a","var_b", ...)
  
  pos1 &lt;- which(colnames(prod_dev) %in% num_var)
  pos2 &lt;- which(colnames(prod_dev) %in% cat_var)
  
  prod_model_tbl &lt;- prod_dev %&gt;% 
                  mutate(age = 2016- as.numeric(substr(dob_yyyymmdd,1,4))) %&gt;%
                  mutate(msa_fg = ifelse(is.na(msacode2000), 0, 1)) %&gt;% 
                  mutate(csa_fg = ifelse(is.na(csacode), 0, 1)) %&gt;%
                  mutate_each(funs(factor), pos2) %&gt;%
                  mutate_each(funs(as.numeric), pos1)
  </code></pre>
  
  <p>The code will work if prod_dev is a R data frame. But using it on a Spark Data frame does not seem to produce the correct result:</p>
  
  <pre><code>&gt; head(prod_model_tbl)
  
  
      Source:   query [?? x 99]
      Database: spark connection master=yarn-client app=sparklyr_test local=FALSE
  
      Error: org.apache.spark.sql.AnalysisException: undefined function     FACTOR; line 97 pos 2248 at org.apache.spark.sql.hive.HiveFunctionRegistry....
  </code></pre>
  
  <p>Can someone please advise how to make the desired changes to the Spark Data Frame?</p>