I just start using R for statistical analysis and I am still learning. I have an issue with creating loops in R. I have the following case and I was wondering if any one can help me with it. For me is seems impossible but for some of you it is just a piece of cake. I have a data set for different firms across different years. for each firm I have a quarterly earnings data and I need to calculate the median of earnings for each firm for each year: the data set I have is just like the following:
Date Firm Earnings
1Q 2009 A 1000
2Q 2009 A 1500
3Q 2009 A 500
4Q 2009 A 2000
1Q 2010 A 1200
2Q 2010 A 1800
3Q 2010 A 2100
4Q 2010 A 2500
1Q 2009 B 1750
2Q 2009 B 2400
3Q 2009 B 3000
4Q 2009 B 2050
.
.
the result I need is like the following
Year Firm Median
2009 A 1250
2010 A 1950
2009 B 2225
2010 B ....
I hope you can help me with this issue. thank you in advance :)