[R] Conditional Statistics
Joseph Norman Thomson
thomsonj at email.arizona.edu
Tue Jan 8 02:17:27 CET 2013
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
More information about the R-help
mailing list