Search code examples
rmeanxtsstandard-deviation

Mean and SD of whole column with xts


might be a simple question but I am having trouble trying to get the mean and standard deviation over a whole period 2007-2019 from a xts object and not just the yearly info. Is there a way to do this all at once?

apply.yearly(zxl$logs, mean) apply.yearly(zxl$logs, sd)

Data

            open    high    low    close    volume  adjusted    logs
2007-01-02  7.76    7.80    7.72    7.79    469679  4.320257    NA
2007-01-03  7.80    7.80    7.71    7.72    603550  4.281435    -0.009026496
2007-01-04  7.71    7.86    7.71    7.82    2184809 4.336895    0.012870191
2007-01-05  7.82    8.04    7.79    7.90    2689292 4.381261    0.010178205
2007-01-08  7.97    7.97    7.67    7.69    1284530 4.264797    -0.026941976
2007-01-09  7.72    7.81    7.71    7.72    1904052 4.281435    0.003893581
2007-01-10  7.65    7.80    7.64    7.67    931877  4.253706    -0.006497749
2007-01-11  7.65    7.67    7.56    7.60    955782  4.214884    -0.009168368
2007-01-12  7.63    7.81    7.61    7.75    1002917 4.298072    0.019544596

Solution

  • Not sure if I understand completely, but did you try mean(zxl$logs), sd(zxl$logs)? That should do it over the entire dataset.

    If you want to restrict to a period, you could just do

    mean(zxl['2007-01/2019-01']$logs)