Q:

Doing Calculations In Spark(R)

I am using the sparklyr library. 
I have a variable, wtd which I copied to spark:
copy_to(sc,wtd)
colnames(wtd) <- c("a","b","c","d","e","f","g")

Then I want to do a computation and store that in spark, not in my environment in R.
When I try:
sdf_register(wtd %>% group_by(c,b) %>% filter(row_number()==1) %>%count(d), "wtd2")

Error in UseMethod("sdf_register") : 
  no applicable method for 'sdf_register' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"

The command wtd2 = wtd %>% group_by(c,b) %>% filter(row_number()==1) %>%count(d) works correctly, but that will store it in my environment, not in spark. 

A:

The first argument in your sequence of operations should be a "tbl_spark", not a regular data.frame.  Your command,
wtd2 = wtd %>% group_by(c,b) %>% filter(row_number()==1) %>%count(d)

works because you are not using Spark at all, just normal R data.frames. 
If you want to use it with spark, first, store the spark_tbl variable that is returned when you copy your data.frame:
colnames(wtd) <- c("a","b","c","d","e","f","g")
wtd_tbl <- copy_to(sc, wtd)

Then, you can execute your data pipeline using sdf_register(wtd_tbl %>% ..., "wtd2"). 
If you execute the pipeline as defined, you will get an exception saying:
Error: org.apache.spark.sql. AnalysisException: Window function rownumber() requires window to be ordered

This is because in order to use row_number() in Spark, first you need to provide an "order function".  You can have this with arrange().  I assume that you want your rows ordered by the columns "c" and "b", so your final pipeline would be something like this:
sdf_register(wtd_tbl %>% 
               dplyr::group_by(c, b) %>% 
               arrange(c, b) %>% 
               dplyr::filter(row_number() == 1) %>% 
               dplyr::count(d),
             "wtd2")

I hope this helps.