Examples for 'base::eapply'


Apply a Function Over Values in an Environment

Aliases: eapply

Keywords: iteration environment list

### ** Examples

require(stats)

env <- new.env(hash = FALSE) # so the order is fixed
env$a <- 1:10
env$beta <- exp(-3:3)
env$logic <- c(TRUE, FALSE, FALSE, TRUE)
# what have we there?
utils::ls.str(env)
a :  int [1:10] 1 2 3 4 5 6 7 8 9 10
beta :  num [1:7] 0.0498 0.1353 0.3679 1 2.7183 ...
logic :  logi [1:4] TRUE FALSE FALSE TRUE
# compute the mean for each list element
       eapply(env, mean)
$logic
[1] 0.5

$beta
[1] 4.535125

$a
[1] 5.5
unlist(eapply(env, mean, USE.NAMES = FALSE))
[1] 0.500000 4.535125 5.500000
# median and quartiles for each element (making use of "..." passing):
eapply(env, quantile, probs = 1:3/4)
$logic
25% 50% 75% 
0.0 0.5 1.0 

$beta
      25%       50%       75% 
0.2516074 1.0000000 5.0536690 

$a
 25%  50%  75% 
3.25 5.50 7.75 
eapply(env, quantile)
$logic
  0%  25%  50%  75% 100% 
 0.0  0.0  0.5  1.0  1.0 

$beta
         0%         25%         50%         75%        100% 
 0.04978707  0.25160736  1.00000000  5.05366896 20.08553692 

$a
   0%   25%   50%   75%  100% 
 1.00  3.25  5.50  7.75 10.00 

[Package base version 4.2.3 Index]