[R] Conditional Statistics

John Kane jrkrideau at inbox.com
Tue Jan 8 14:05:20 CET 2013

I think Simon has provided a good answer to the actual question but as a refugee from SAS I'd suggest having a look at www.et.bs.ehu.es/~etptupaf/pub/R/RforSAS&SPSSusers.pdf or getting the book Muenchen, R. A. (2008). R for SAS and SPSS Users (1st ed.). Springer.

R ans SAS approach things very differently at times.

John Kane
Kingston ON Canada

> -----Original Message-----
> From: thomsonj at email.arizona.edu
> Sent: Mon, 7 Jan 2013 19:17:27 -0600
> To: r-help at r-project.org
> Subject: [R] Conditional Statistics
> Hello,
> I am a new user of R. I am coming from SAS and do statistics on stock
> market data, economic data, and social data. My question is this: How
> can you get the mean, standard dev, etc. of a variable based on a
> conditional statement on either the same variable or a different
> variable in the same data set? So if I had the closing prices of the
> S&P from 01/01/1990-12/31/1990, how could I get the average price of
> the S&P from 02/01/1990-03/15/1990? Or the average price of the S&P on
> Mondays (assuming a dummy var is created for 1 = Monday, 0 = else). I
> understand that you can create subsets and new data sets based on the
> conditional statements; but is there an easier way to do this by
> typing a line into the mean() statement? That was extremely easy in
> SAS where you could say:
> proc means data=sp500;
> var price;
> where monday = 1;
> Thank you for your help.
> Joe
> ______________________________________________
> R-help at r-project.org mailing list
> 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.

FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!

More information about the R-help mailing list