These functions allow easily computing means and sums. Note that if you attach rosetta to the search path,

means(
  ...,
  data = NULL,
  requiredValidValues = 0,
  returnIfInvalid = NA,
  silent = FALSE
)

sums(
  ...,
  data = NULL,
  requiredValidValues = 0,
  returnIfInvalid = NA,
  silent = FALSE
)

Arguments

...

The dataframe or vectors for which to compute the means or sums. When passing a dataframe as unnamed argument (i.e. in the "dots", ...), the means or sums for all columns in the dataframe will be computed. If you want to select one or more columns, make sure to pass the dataframe as data.

data

If a dataframe is passed as data, the values passed in the "dots" (...) will be taken as column names or indices in that dataframe. This allows easy indexing.

requiredValidValues

The number (if larger than 1) or proportion (if between 0 and 1) of values that have to be valid (i.e. nonmissing) before the mean or sum is returned.

returnIfInvalid

Which value to return for rows not meeting the criterion specified in requiredValidValues.

silent

Whether to suppress messages.

Value

The means or sums.

Examples

rosetta::means(mtcars$mpg, mtcars$disp, mtcars$wt);
#>  [1]  61.20667  61.29167  44.37333  94.20500 127.38000  82.18667 125.95667
#>  [8]  58.09667  55.58333  63.41333  62.94667  98.75667  98.94333  98.26000
#> [15] 162.55000 158.60800 153.34833  37.76667  35.90500  35.61167  48.02167
#> [22] 112.34000 107.54500 122.38000 141.01500  36.07833  49.48000  42.33767
#> [29] 123.32333  55.82333 106.52333  48.39333
rosetta::means(data=mtcars, 'mpg', 'disp', 'wt');
#>           Mazda RX4       Mazda RX4 Wag          Datsun 710      Hornet 4 Drive 
#>            61.20667            61.29167            44.37333            94.20500 
#>   Hornet Sportabout             Valiant          Duster 360           Merc 240D 
#>           127.38000            82.18667           125.95667            58.09667 
#>            Merc 230            Merc 280           Merc 280C          Merc 450SE 
#>            55.58333            63.41333            62.94667            98.75667 
#>          Merc 450SL         Merc 450SLC  Cadillac Fleetwood Lincoln Continental 
#>            98.94333            98.26000           162.55000           158.60800 
#>   Chrysler Imperial            Fiat 128         Honda Civic      Toyota Corolla 
#>           153.34833            37.76667            35.90500            35.61167 
#>       Toyota Corona    Dodge Challenger         AMC Javelin          Camaro Z28 
#>            48.02167           112.34000           107.54500           122.38000 
#>    Pontiac Firebird           Fiat X1-9       Porsche 914-2        Lotus Europa 
#>           141.01500            36.07833            49.48000            42.33767 
#>      Ford Pantera L        Ferrari Dino       Maserati Bora          Volvo 142E 
#>           123.32333            55.82333           106.52333            48.39333 
rosetta::sums(mtcars$mpg, mtcars$disp, mtcars$wt);
#>  [1] 183.620 183.875 133.120 282.615 382.140 246.560 377.870 174.290 166.750
#> [10] 190.240 188.840 296.270 296.830 294.780 487.650 475.824 460.045 113.300
#> [19] 107.715 106.835 144.065 337.020 322.635 367.140 423.045 108.235 148.440
#> [28] 127.013 369.970 167.470 319.570 145.180
rosetta::sums(data=mtcars, 'mpg', 'disp', 'wt');
#>           Mazda RX4       Mazda RX4 Wag          Datsun 710      Hornet 4 Drive 
#>             183.620             183.875             133.120             282.615 
#>   Hornet Sportabout             Valiant          Duster 360           Merc 240D 
#>             382.140             246.560             377.870             174.290 
#>            Merc 230            Merc 280           Merc 280C          Merc 450SE 
#>             166.750             190.240             188.840             296.270 
#>          Merc 450SL         Merc 450SLC  Cadillac Fleetwood Lincoln Continental 
#>             296.830             294.780             487.650             475.824 
#>   Chrysler Imperial            Fiat 128         Honda Civic      Toyota Corolla 
#>             460.045             113.300             107.715             106.835 
#>       Toyota Corona    Dodge Challenger         AMC Javelin          Camaro Z28 
#>             144.065             337.020             322.635             367.140 
#>    Pontiac Firebird           Fiat X1-9       Porsche 914-2        Lotus Europa 
#>             423.045             108.235             148.440             127.013 
#>      Ford Pantera L        Ferrari Dino       Maserati Bora          Volvo 142E 
#>             369.970             167.470             319.570             145.180