@@ -1314,7 +1314,7 @@ setMethod("except",
13141314# ' write.df(df, "myfile", "parquet", "overwrite")
13151315# ' }
13161316setMethod ("write.df ",
1317- signature(df = " DataFrame" , path = ' character' ),
1317+ signature(df = " DataFrame" , path = " character" ),
13181318 function (df , path , source = NULL , mode = " append" , ... ){
13191319 if (is.null(source )) {
13201320 sqlContext <- get(" .sparkRSQLsc" , envir = .sparkREnv )
@@ -1328,7 +1328,7 @@ setMethod("write.df",
13281328 jmode <- callJStatic(" org.apache.spark.sql.api.r.SQLUtils" , " saveMode" , mode )
13291329 options <- varargsToEnv(... )
13301330 if (! is.null(path )) {
1331- options [[' path' ]] = path
1331+ options [[" path" ]] <- path
13321332 }
13331333 callJMethod(df @ sdf , " save" , source , jmode , options )
13341334 })
@@ -1337,7 +1337,7 @@ setMethod("write.df",
13371337# ' @aliases saveDF
13381338# ' @export
13391339setMethod ("saveDF ",
1340- signature(df = " DataFrame" , path = ' character' ),
1340+ signature(df = " DataFrame" , path = " character" ),
13411341 function (df , path , source = NULL , mode = " append" , ... ){
13421342 write.df(df , path , source , mode , ... )
13431343 })
@@ -1375,8 +1375,8 @@ setMethod("saveDF",
13751375# ' saveAsTable(df, "myfile")
13761376# ' }
13771377setMethod ("saveAsTable ",
1378- signature(df = " DataFrame" , tableName = ' character' , source = ' character' ,
1379- mode = ' character' ),
1378+ signature(df = " DataFrame" , tableName = " character" , source = " character" ,
1379+ mode = " character" ),
13801380 function (df , tableName , source = NULL , mode = " append" , ... ){
13811381 if (is.null(source )) {
13821382 sqlContext <- get(" .sparkRSQLsc" , envir = .sparkREnv )
@@ -1554,3 +1554,31 @@ setMethod("fillna",
15541554 }
15551555 dataFrame(sdf )
15561556 })
1557+
1558+ # ' crosstab
1559+ # '
1560+ # ' Computes a pair-wise frequency table of the given columns. Also known as a contingency
1561+ # ' table. The number of distinct values for each column should be less than 1e4. At most 1e6
1562+ # ' non-zero pair frequencies will be returned.
1563+ # '
1564+ # ' @param col1 name of the first column. Distinct items will make the first item of each row.
1565+ # ' @param col2 name of the second column. Distinct items will make the column names of the output.
1566+ # ' @return a local R data.frame representing the contingency table. The first column of each row
1567+ # ' will be the distinct values of `col1` and the column names will be the distinct values
1568+ # ' of `col2`. The name of the first column will be `$col1_$col2`. Pairs that have no
1569+ # ' occurrences will have `null` as their counts.
1570+ # '
1571+ # ' @rdname statfunctions
1572+ # ' @export
1573+ # ' @examples
1574+ # ' \dontrun{
1575+ # ' df <- jsonFile(sqlCtx, "/path/to/file.json")
1576+ # ' ct = crosstab(df, "title", "gender")
1577+ # ' }
1578+ setMethod ("crosstab ",
1579+ signature(x = " DataFrame" , col1 = " character" , col2 = " character" ),
1580+ function (x , col1 , col2 ) {
1581+ statFunctions <- callJMethod(x @ sdf , " stat" )
1582+ sct <- callJMethod(statFunctions , " crosstab" , col1 , col2 )
1583+ collect(dataFrame(sct ))
1584+ })
0 commit comments