spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun-rui <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-10752][SPARKR] Implement corr() and cov...
Date Tue, 29 Sep 2015 06:51:26 GMT
Github user sun-rui commented on a diff in the pull request:

    https://github.com/apache/spark/pull/8869#discussion_r40639291
  
    --- Diff: R/pkg/R/DataFrameStatFunctions.R ---
    @@ -0,0 +1,102 @@
    +#
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You under the Apache License, Version 2.0
    +# (the "License"); you may not use this file except in compliance with
    +# the License.  You may obtain a copy of the License at
    +#
    +#    http://www.apache.org/licenses/LICENSE-2.0
    +#
    +# Unless required by applicable law or agreed to in writing, software
    +# distributed under the License is distributed on an "AS IS" BASIS,
    +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    +# See the License for the specific language governing permissions and
    +# limitations under the License.
    +#
    +
    +# DataFrameStatFunctions.R - Statistic functions for DataFrames.
    +
    +setOldClass("jobj")
    +
    +#' crosstab
    +#'
    +#' Computes a pair-wise frequency table of the given columns. Also known as a contingency
    +#' table. The number of distinct values for each column should be less than 1e4. At most
1e6
    +#' non-zero pair frequencies will be returned.
    +#'
    +#' @param col1 name of the first column. Distinct items will make the first item of each
row.
    +#' @param col2 name of the second column. Distinct items will make the column names of
the output.
    +#' @return a local R data.frame representing the contingency table. The first column
of each row
    +#'         will be the distinct values of `col1` and the column names will be the distinct
values
    +#'         of `col2`. The name of the first column will be `$col1_$col2`. Pairs that
have no
    +#'         occurrences will have zero as their counts.
    +#'
    +#' @rdname statfunctions
    +#' @name crosstab
    +#' @export
    +#' @examples
    +#' \dontrun{
    +#' df <- jsonFile(sqlCtx, "/path/to/file.json")
    +#' ct <- crosstab(df, "title", "gender")
    +#' }
    +setMethod("crosstab",
    +          signature(x = "DataFrame", col1 = "character", col2 = "character"),
    +          function(x, col1, col2) {
    +            statFunctions <- callJMethod(x@sdf, "stat")
    +            sct <- callJMethod(statFunctions, "crosstab", col1, col2)
    +            collect(dataFrame(sct))
    +          })
    +
    +#' cov
    +#'
    +#' Calculate the sample covariance of two numerical columns of a DataFrame.
    +#'
    +#' @param x A SparkSQL DataFrame
    +#' @param col1 the name of the first column
    +#' @param col2 the name of the second column
    +#' @return the covariance of the two columns.
    +#'
    +#' @rdname statfunctions
    +#' @name cov
    +#' @export
    +#' @examples
    +#'\dontrun{
    +#' df <- jsonFile(sqlCtx, "/path/to/file.json")
    +#' cov <- cov(df, "title", "gender")
    +#' }
    +setMethod("cov",
    +          signature(x = "DataFrame", col1 = "character", col2 = "character"),
    --- End diff --
    
    @NarineK, thank you for your comments. You suggestion needs extensions to Scala DataFrame.
I prefer that you can submit a new JIRA in the community. @shivaram, what do you think?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message