From 537998bf3b1eb4e7f2771d5c53f5f2fbc472a25a Mon Sep 17 00:00:00 2001 From: Nicolau Manubens Date: Mon, 22 Oct 2018 20:03:09 +0200 Subject: [PATCH 1/2] Updated Readme. --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a6cfa35..ac934e1 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,51 @@ ---- -title: "Apply a Function Taking Multiple Numeric Objects as Input Across Multiple Arrays" -author: "Alasdair" -date: "14 July 2017" -output: html_document ---- +## Apply a Function Taking Multiple Numeric Objects as Input Across Multiple Arrays This package extends the apply and plyr families of functions to applications which involve the use of multiple arrays as input. -This is especially useful for climate data related applications, where data is often distributed across multiple arrays with different dimensions (e.g experimental array 1, experimental array 2 and the observations). The multiApply:Apply function reduces the need write loops for every application. +This is especially useful for climate data related applications, where data is often distributed across multiple arrays with different dimensions (e.g experimental array 1, experimental array 2 and the observations). The multiApply::Apply function reduces the need to write loops for every application. +### Installation +In order to install and load the latest published version of the package on CRAN, you can run the following lines in your R session: + +```r +install.packages('multiApply') +library(multiApply) +``` + +Also, you can install the latest stable version from this GitHub repository as follows: + +```r +devtools::install_git('https://earth.bsc.es/gitlab/ces/multiApply') +``` + +### How to use + +This package consistis in a single function, `Apply`, which is used in a similar fashion as the base `apply`. Full documentation can be found in `?Apply`. + +A simple example is provided next. In this example, we have two data arrays. The first, with information on the number of items sold in 5 different stores (located in different countries) during the past 1000 days, for 200 different items. The second, with information on the price point for each item in each store. + +The example shows how to compute the total income for each of the stores, straightforwardly combining the input data arrays, by automatically applying repeatedly the 'atomic' function that performs only the essential calculations for a single case. + +```r +dims <- c(store = 5, item = 200, day = 1000) +sales_amount <- array(rnorm(prod(dims)), dims) + +dims <- c(store = 5, item = 200) +sales_price <- array(rnorm(prod(dims)), dims) + +income_function <- function(x, y) { + # Expected inputs: + # x: array with dimensions (item, day) + # y: price point vector with dimension (item) + sum(rowSums(x) * y) +} + +income <- Apply(data = list(sales_amount, sales_price), + target_dims = list(c('item', 'day'), 'item'), + income_function) + +dim(income[[1]]) +# store +# 5 +``` -- GitLab From 82ce62c4f26df8e50a73a7590f431ff9db657d66 Mon Sep 17 00:00:00 2001 From: Nicolau Manubens Date: Mon, 22 Oct 2018 20:07:56 +0200 Subject: [PATCH 2/2] Small fixes in readme. --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ac934e1..5450824 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -## Apply a Function Taking Multiple Numeric Objects as Input Across Multiple Arrays +## multiApply -This package extends the apply and plyr families of functions to applications which involve the use of multiple arrays as input. +This package extends the apply and plyr families of functions to applications which involve the use of multiple arrays as input, and is useful to apply a function taking multiple numeric objects as input across multiple multi-dimensional arrays. -This is especially useful for climate data related applications, where data is often distributed across multiple arrays with different dimensions (e.g experimental array 1, experimental array 2 and the observations). The multiApply::Apply function reduces the need to write loops for every application. +This is especially useful for climate data related applications, where data is often distributed across multiple arrays with different dimensions (e.g experimental array 1, experimental array 2 and the observations). The `multiApply::Apply` function reduces the need to write loops for every application. ### Installation -- GitLab