[R] Descriptive Statistics of time series data

David L Carlson dcarlson at tamu.edu
Wed Apr 6 20:50:40 CEST 2016


For mean() and sd() you need to convert the data frame to a matrix (I'm guessing here since you did not show us the structure of your data). The min() and max() functions should work on the data frame just fine. If you have other columns in the data frame, extract the monthly columns first.

> set.seed(42)
> x <- data.frame(matrix(rnorm(100), 20, 5))
> str(x)
'data.frame':   20 obs. of  5 variables:
 $ X1: num  1.371 -0.565 0.363 0.633 0.404 ...
 $ X2: num  -0.307 -1.781 -0.172 1.215 1.895 ...
 $ X3: num  0.206 -0.361 0.758 -0.727 -1.368 ...
 $ X4: num  -0.367 0.185 0.582 1.4 -0.727 ...
 $ X5: num  1.5127 0.2579 0.0884 -0.1209 -1.1943 ...
> mean(as.matrix(x))
[1] 0.03251482
> sd(as.matrix(x))
[1] 1.041357
> min(x)
[1] -2.99309
> max(x)
[1] 2.286645

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Saba Sehrish via R-help
Sent: Wednesday, April 6, 2016 6:51 AM
To: r-help at r-project.org
Subject: [R] Descriptive Statistics of time series data

Hi

I have four variables and the time series data for each variable consists of values for past 10 years on monthly basis. I want to get descriptive stats for these four variables separately (mean, median, sd, min, max).

The data I import to R consists of different columns, where each column gives values for one month of a particular year (e.g. March 31st, 2010). Right now R gives descriptive results for each column, whereas I need it collectively for all the years ( one mean, one sd, one min, one max and one median) for each variable.

Kindly guide me in this regard.

Thanks.
Saba

Sent from Yahoo Mail on Android


	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list