[R] Building correlation matrix

Jason Morgan jwm-r-help at skepsi.net
Tue May 25 18:53:40 CEST 2010

On 2010.05.25 11:52:07, Anyi Zhu wrote:
> Hi,
> I am a novice with R, so pardon me if the question is a piece of cake
> to some of you.
> Say if I have a stream of data consisting of 3 columns, 1st column is
> birth date, 2nd is death date and third is weight for each individual.
> My ultimate goal is to be able to compute the correlation of weight
> between any combination of two death dates, grouped by birth dates.
> In order to do this, my plan is to be able to use a loop of some sorts
> to split the data into n vectors, each vector consists of all birth
> dates and weight for people who are dead on the same death date. Then
> figure out the standard deviation and covariance of each of the
> combination of the vectors, figure out the correlation and finally
> bind them into a matrix (or at least a 3 column table: death date1,
> death date 2, correlation).
> The only problem is I know how to implement this in SQL/Excel but not in R.
> Could someone please offer me some guidance on this? Thanks a lot!

Hello Anyi,

I suggest you take a look at the plyr package. It allows you to easily
subset a data.frame and apply any function to that data.frame.


Jason W. Morgan
Graduate Student
Department of Political Science
*The Ohio State University*
154 North Oval Mall
Columbus, Ohio 43210

More information about the R-help mailing list