I want to do one-sample t-test for 'ret' and get the p_value for each var for every year. Thank you very much!
I just know the simple code as follows:
t_value = t.test(ret, mu = 0, alternative = "two.sided")
p_value = t_value$p.value
But here the data format is as follows, so how could I do t.test group by var and year, and get p_value for each var for each year.
date var ret
192801 DivSeason 0.010634922
192802 DivSeason -0.009563514
192803 DivSeason -0.024472939
192804 DivSeason 0.02416725
192805 DivSeason -0.003952754
192707 IntMom 0.100446374
192708 IntMom 0.082850599
192709 IntMom 0.033624589
192710 IntMom 0.000342533
192711 IntMom -0.063029611
192712 IntMom -0.026919169
192801 IntMom -0.028079162
192802 IntMom -0.040030694
192803 IntMom 0.001822507
192804 IntMom -0.124844386
192805 IntMom 0.032536945
192608 Size 0.016160115
192609 Size -0.00558869
192610 Size -0.001729607
192611 Size -0.040041879
192612 Size -0.019211495
192701 Size 0.026387598
192702 Size 0.004592343
192703 Size -0.041916542
192704 Size 0.042546142
192705 Size 0.017505246
192706 Size -0.018159825