Code Monkey home page Code Monkey logo

afp's Introduction

afp's People

Contributors

robertschnitman avatar

afp's Issues

mtapply()? Multivariate tapply()

Work on code and documentation. Input names to be consistent with tapply().

Example build:

mtapply <- function(X, INDEX, FUN = NULL, ...) {
  
  tapfun <- function(a, b) tapply(a, b, FUN) # Writing the tapply() on this line makes the output-assignment line more readable than otherwise.
  
  output <- mapply(tapfun, X, INDEX, ...)
  
  output                                     # Output should be a matrix or list. See tapply documentation.
  
}

PROOFREAD - .R & .Rd files

Glances at a few of the .R files are shown to have grammatical errors (primarily redundancies). For example, the error message in do.bind.R mentions the "rc" input instead of "m" (margin).

rc

mapreducem() - multivariate mapreduce (combine?)

Should a multivariate version of mapreduce() be produced so that mapreduce() is consistent with its Julian origin, or should it be inherently multivariate to be consistent with Map()/mapply()?

Example Code
mapreducem <- function(f, o, x, y = NULL, ...) {
f <- match.fun(f)
o <- match.fun(o)

output <- Reduce(o, mapply(f, x, MoreArgs = y, SIMPLIFY = FALSE), ...)
output

}

Other functions - README.md vs. separate document(s)

The primary functions--do.bind(), mapreduce(), and telecast()--are described in the current README.md. Should the other functions be included in said document, or explained in a separate document (perhaps multiple)?

Type/class-matching for relevant apply/map functions

Proposal

For the relevant functions, include an input that specifies which variables to limit the mapping based on class of the variable (in a 2D array) or list element (presuming that it is at least a vector).

Context

The function rapply() has an input classes that limits where the input function applies. For example, specifying classes = 'numeric' tells rapply() to apply a function only on the numeric list elements.

ex_rapply <- rapply(iris, mean, classes = 'numeric') # Ignores Species column.

ex_rapply
Sepal.Length  Sepal.Width Petal.Length  Petal.Width 
    5.843333     3.057333     3.758000     1.199333 

One can achieve the same results with a combination of sapply() and Filter().

ex_sapply <- sapply(Filter(is.numeric, iris), mean)

all(ex_sapply == ex_rapply)
[1] TRUE

However, an issue with rapply() is that the data input is required to be a list; so, the sapply()/Filter() method is recommended when having complex filter conditions for matrices.

Alternatively, the proposed hypothetical input would save the user time via establishing the logical condition within the function, which would avoid vector sequences, name matching, or the previously mentioned method of sapply()/Filter().

Example of modifying mrchop()

mrchop <- function(f, o, x, m, filter = is.numeric, ...) {  
  
  x_filter <- Filter(filter, x) # Only variables matching the filter condition.

  output <- apply(x_filter, m, function(z) mapreduce(f, o, z, y = NULL, ...))  

  output

}

meep() - multivariate sweep()?

The function sweep() is underrated. So, to expand upon its benefits, how should a multivariate version of sweep() resemble?

# Rough draft
meep <- function(f, s, x, ..., keep.rownames = FALSE) { 
# function, summary statistic, dataset, mapply inputs, rownames condition
 
  output <- mapply(function(y) f(y, s(y)), x, ...)
  
  cond_len <- length(NROW(x)) == length(NROW(output))
  
  if (length(dim(x)) > 1) {
    
    if (keep.rownames == TRUE & cond_len == FALSE) {
      
      stop('length(NROW(x)) != length(NROW(output))')
      
    } else if (keep.rownames == TRUE & cond_len == TRUE) {
      
      rownames(output) <- rownames(x)
      
    }
    
  }
  
  output
  
}

# Example
meep(`/`, mean, mtcars, keep.rownames = TRUE)

mapdims - grave accents appearing for rowwise and not colwise

ISSUE: The output in mapdims() produces grave accents (`) for the name of the row results; however, it was not the case for the column-wise list element. Why the inconsistency?

Attempts to remove the grave accents were not successful at this point: initial methods employed to overwrite the names were the assignment operator, make.names(), and gsub().

Example

> mapdims(median, mtcars)
$`rowwise`
          Mazda RX4       Mazda RX4 Wag          Datsun 710      Hornet 4 Drive 
           29.90727            29.98136            23.59818            38.73955 
  Hornet Sportabout             Valiant          Duster 360           Merc 240D 
           53.66455            35.04909            59.72000            24.63455 
           Merc 230            Merc 280           Merc 280C          Merc 450SE 
           27.23364            31.86000            31.78727            46.43091 
         Merc 450SL         Merc 450SLC  Cadillac Fleetwood Lincoln Continental 
           46.50000            46.35000            66.23273            66.05855 
  Chrysler Imperial            Fiat 128         Honda Civic      Toyota Corolla 
           65.97227            19.44091            17.74227            18.81409 
      Toyota Corona    Dodge Challenger         AMC Javelin          Camaro Z28 
           24.88864            47.24091            46.00773            58.75273 
   Pontiac Firebird           Fiat X1-9       Porsche 914-2        Lotus Europa 
           57.37955            18.92864            24.77909            24.88027 
     Ford Pantera L        Ferrari Dino       Maserati Bora          Volvo 142E 
           60.97182            34.50818            63.15545            26.26273 

$colwise
       mpg        cyl       disp         hp       drat         wt       qsec 
 20.090625   6.187500 230.721875 146.687500   3.596563   3.217250  17.848750 
        vs         am       gear       carb 
  0.437500   0.406250   3.687500   2.812500 

Supplemental documentation for all functions

A new folder docs has been created The plan is to have markdown documents that explain each function, acting as supplements to the .Rd files.

Documents pending

  • agg
  • bcast
    • .
  • do.bind
  • mapdims
  • mapreduce
    • mrchop
    • reducechop
  • mop
  • mtapply
  • telecast

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.