Eddington | R Documentation |
The class will maintain the state of the algorithm, allowing for efficient updates as new rides come in.
The implementation uses an experimental base R feature utils::hashtab.
Cloning of Eddington
objects is disabled. Additionally, Eddington
objects
cannot be serialized; they cannot be carried between sessions using
base::saveRDS or base::save and then loaded later using base::readRDS
or base::load.
current
The current Eddington number.
cumulative
A vector of cumulative Eddington numbers.
number_to_next
The number of rides needed to get to the next Eddington number.
n
The number of rides in the data.
hashmap
The hash map of rides above the current Eddington number.
new()
Create a new Eddington object.
Eddington$new(rides, store.cumulative = FALSE)
rides
A vector of rides
store.cumulative
logical, indicating whether to keep a vector of cumulative Eddington numbers
A new Eddington
object
print()
Print the current Eddington number.
Eddington$print()
update()
Add new rides to the existing Eddington
object.
Eddington$update(rides)
rides
A vector of rides
getNumberToTarget()
Get the number of rides of a specified length to get to a target Eddington number.
Eddington$getNumberToTarget(target)
target
Target Eddington number
An integer representing the number of rides of target length needed to achieve the target number.
isSatisfied()
Test if an Eddington number is satisfied.
Eddington$isSatisfied(target)
target
Target Eddington number
Logical
# Randomly generate a set of 15 rides
rides <- rgamma(15, shape = 2, scale = 10)
# View the rides sorted in decreasing order
stats::setNames(sort(rides, decreasing = TRUE), seq_along(rides))
# Create the Eddington object
e <- Eddington$new(rides, store.cumulative = TRUE)
# Get the Eddington number
e$current
# Update with new data
e$update(rep(25, 10))
# See the new data
e$cumulative
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.