Learn R Programming

eList (version 0.0.1.0)

comprehendSummary: Vectorized Comprehension and Summary

Description

Functions that summarize the results of a Python-style comprehension. These functions extend those in comprehension by applying a post-evaluation function to the results of the loop.

Usage

All(..., clust = NULL, na.rm = FALSE)

Any(..., clust = NULL, na.rm = FALSE)

None(..., clust = NULL, na.rm = FALSE)

Sum(..., clust = NULL, na.rm = FALSE)

Prod(..., clust = NULL, na.rm = FALSE)

Min(..., clust = NULL, na.rm = FALSE)

Max(..., clust = NULL, na.rm = FALSE)

Mean(..., clust = NULL, na.rm = FALSE, trim = 0)

Stats(..., clust = NULL, na.rm = FALSE, trim = 0)

Paste(..., clust = NULL, collapse = "")

Arguments

...

vectors of any type or a for loop with format: for (var in seq) <name => <if (cond)> expr. See comprehension.

clust

cluster to use for parallel computations

na.rm

logical; should missing values be removed? Defaults to FALSE

trim

fraction between 0 and 0.5 describing percent of observations to be trimmed from each side for the mean

collapse

character describing how the results from Paste should be collapsed. See paste.

Value

Single numeric or character value, or a list of results for Stats

Functions

  • All: Are all results TRUE?

  • Any: Are any results TRUE?

  • None: Are all results FALSE?

  • Sum: Calculate the sum of results

  • Prod: Calculate the prod of results

  • Min: Find the minimum in the result

  • Max: Find the maximum in the result

  • Mean: Calculate the arithmetic mean of the result

  • Stats: Find the 7 number summary (5 number + mean & sd) of the result

  • Paste: Collapse the result into a single character

Examples

Run this code
# NOT RUN {
## Calculate the sum of all even numbers to 100
Sum(for (i in seq(2, 100, 2)) i)

## Find the mean
Mean(for (i in 1:10) log(i))

## Combine character values
greet <- c("Hello", "World", "Nice", "To", "Meet", "You")
val <- Paste(for (i.j in enum(greet)) paste0(i, ": ", j), collapse="\n")
cat(val)

# }

Run the code above in your browser using DataLab