@@ -255,6 +255,16 @@ setMethod("names",
255255 columns(x )
256256 })
257257
258+ # ' @rdname columns
259+ setMethod(" names<-" ,
260+ signature(x = " DataFrame" ),
261+ function (x , value ) {
262+ if (! is.null(value )) {
263+ sdf <- callJMethod(x @ sdf , " toDF" , listToSeq(as.list(value )))
264+ dataFrame(sdf )
265+ }
266+ })
267+
258268# ' Register Temporary Table
259269# '
260270# ' Registers a DataFrame as a Temporary Table in the SQLContext
@@ -473,6 +483,18 @@ setMethod("distinct",
473483 dataFrame(sdf )
474484 })
475485
486+ # ' @title Distinct rows in a DataFrame
487+ #
488+ # ' @description Returns a new DataFrame containing distinct rows in this DataFrame
489+ # '
490+ # ' @rdname unique
491+ # ' @aliases unique
492+ setMethod ("unique ",
493+ signature(x = " DataFrame" ),
494+ function (x ) {
495+ distinct(x )
496+ })
497+
476498# ' Sample
477499# '
478500# ' Return a sampled subset of this DataFrame using a random seed.
@@ -534,6 +556,58 @@ setMethod("count",
534556 callJMethod(x @ sdf , " count" )
535557 })
536558
559+ # ' @title Number of rows for a DataFrame
560+ # ' @description Returns number of rows in a DataFrames
561+ # '
562+ # ' @name nrow
563+ # '
564+ # ' @rdname nrow
565+ # ' @aliases count
566+ setMethod ("nrow ",
567+ signature(x = " DataFrame" ),
568+ function (x ) {
569+ count(x )
570+ })
571+
572+ # ' Returns the number of columns in a DataFrame
573+ # '
574+ # ' @param x a SparkSQL DataFrame
575+ # '
576+ # ' @rdname ncol
577+ # ' @export
578+ # ' @examples
579+ # '\dontrun{
580+ # ' sc <- sparkR.init()
581+ # ' sqlContext <- sparkRSQL.init(sc)
582+ # ' path <- "path/to/file.json"
583+ # ' df <- jsonFile(sqlContext, path)
584+ # ' ncol(df)
585+ # ' }
586+ setMethod ("ncol ",
587+ signature(x = " DataFrame" ),
588+ function (x ) {
589+ length(columns(x ))
590+ })
591+
592+ # ' Returns the dimentions (number of rows and columns) of a DataFrame
593+ # ' @param x a SparkSQL DataFrame
594+ # '
595+ # ' @rdname dim
596+ # ' @export
597+ # ' @examples
598+ # '\dontrun{
599+ # ' sc <- sparkR.init()
600+ # ' sqlContext <- sparkRSQL.init(sc)
601+ # ' path <- "path/to/file.json"
602+ # ' df <- jsonFile(sqlContext, path)
603+ # ' dim(df)
604+ # ' }
605+ setMethod ("dim ",
606+ signature(x = " DataFrame" ),
607+ function (x ) {
608+ c(count(x ), ncol(x ))
609+ })
610+
537611# ' Collects all the elements of a Spark DataFrame and coerces them into an R data.frame.
538612# '
539613# ' @param x A SparkSQL DataFrame
@@ -1231,6 +1305,22 @@ setMethod("unionAll",
12311305 dataFrame(unioned )
12321306 })
12331307
1308+ # ' @title Union two or more DataFrames
1309+ #
1310+ # ' @description Returns a new DataFrame containing rows of all parameters.
1311+ #
1312+ # ' @rdname rbind
1313+ # ' @aliases unionAll
1314+ setMethod ("rbind ",
1315+ signature(... = " DataFrame" ),
1316+ function (x , ... , deparse.level = 1 ) {
1317+ if (nargs() == 3 ) {
1318+ unionAll(x , ... )
1319+ } else {
1320+ unionAll(x , Recall(... , deparse.level = 1 ))
1321+ }
1322+ })
1323+
12341324# ' Intersect
12351325# '
12361326# ' Return a new DataFrame containing rows only in both this DataFrame
@@ -1322,9 +1412,11 @@ setMethod("write.df",
13221412 " org.apache.spark.sql.parquet" )
13231413 }
13241414 allModes <- c(" append" , " overwrite" , " error" , " ignore" )
1415+ # nolint start
13251416 if (! (mode %in% allModes )) {
13261417 stop(' mode should be one of "append", "overwrite", "error", "ignore"' )
13271418 }
1419+ # nolint end
13281420 jmode <- callJStatic(" org.apache.spark.sql.api.r.SQLUtils" , " saveMode" , mode )
13291421 options <- varargsToEnv(... )
13301422 if (! is.null(path )) {
@@ -1384,9 +1476,11 @@ setMethod("saveAsTable",
13841476 " org.apache.spark.sql.parquet" )
13851477 }
13861478 allModes <- c(" append" , " overwrite" , " error" , " ignore" )
1479+ # nolint start
13871480 if (! (mode %in% allModes )) {
13881481 stop(' mode should be one of "append", "overwrite", "error", "ignore"' )
13891482 }
1483+ # nolint end
13901484 jmode <- callJStatic(" org.apache.spark.sql.api.r.SQLUtils" , " saveMode" , mode )
13911485 options <- varargsToEnv(... )
13921486 callJMethod(df @ sdf , " saveAsTable" , tableName , source , jmode , options )
@@ -1554,3 +1648,31 @@ setMethod("fillna",
15541648 }
15551649 dataFrame(sdf )
15561650 })
1651+
1652+ # ' crosstab
1653+ # '
1654+ # ' Computes a pair-wise frequency table of the given columns. Also known as a contingency
1655+ # ' table. The number of distinct values for each column should be less than 1e4. At most 1e6
1656+ # ' non-zero pair frequencies will be returned.
1657+ # '
1658+ # ' @param col1 name of the first column. Distinct items will make the first item of each row.
1659+ # ' @param col2 name of the second column. Distinct items will make the column names of the output.
1660+ # ' @return a local R data.frame representing the contingency table. The first column of each row
1661+ # ' will be the distinct values of `col1` and the column names will be the distinct values
1662+ # ' of `col2`. The name of the first column will be `$col1_$col2`. Pairs that have no
1663+ # ' occurrences will have zero as their counts.
1664+ # '
1665+ # ' @rdname statfunctions
1666+ # ' @export
1667+ # ' @examples
1668+ # ' \dontrun{
1669+ # ' df <- jsonFile(sqlCtx, "/path/to/file.json")
1670+ # ' ct = crosstab(df, "title", "gender")
1671+ # ' }
1672+ setMethod ("crosstab ",
1673+ signature(x = " DataFrame" , col1 = " character" , col2 = " character" ),
1674+ function (x , col1 , col2 ) {
1675+ statFunctions <- callJMethod(x @ sdf , " stat" )
1676+ sct <- callJMethod(statFunctions , " crosstab" , col1 , col2 )
1677+ collect(dataFrame(sct ))
1678+ })
0 commit comments