[R] Combining tapply() and cor.test()?
Sergey Goriatchev
sergeyg at gmail.com
Thu Feb 22 14:35:06 CET 2007
Hello, fellow R-users.
Let me describe the setup first. I have a data.frame, a sample of
which is reported below:
Company.Name Periods Returns MFR.Factor
350 Wartsila Oyj A 1996-07-31 6.82 0.02
351 Custodia Holding AG 1996-07-31 4.15 -0.02
352 Wartsila Oyj 1996-07-31 7.73 0.09
353 GEA Group AG 1996-07-31 10.12 0.04
354 LEGRAND ORD 1996-07-31 -7.46 -0.20
355 Mayr-Melnhof Karton AG 1996-07-31 4.71 -0.05
356 GEVAERT NPV 1996-08-30 NA NA
357 NOKIA K FMA2.50 1996-08-30 7.65 0.03
358 Altadis S.A. 1996-08-30 7.65 0.55
359 Metrovacesa S.A. 1996-08-30 4.55 -0.17
360 Oce N.V. 1996-08-30 9.43 0.23
The variable "Periods" is a date object, shows the month.
Variables "Returns" and "MFR.Factor" are numeric.
For each month the number of Returns and MFR.Factors varies, sometimes
it is 350, sometimes 320 etc.
What I need is to use cor.test(Returns, MFR.Factor,...) for each
month, and produce a dataframe with columns: "Period", "cor.estimate",
"p.value".
The simplest way would be with tapply() using variable "Period" as a
factor, but tapply() only applies FUN to just one cell.
What is the most painless way to achieve my objective?
Thank you in advance for your help!
Best,
Sergey
More information about the R-help
mailing list