Skip to content
Discussion options

You must be logged in to vote

Yes, this is fine. I would suggest using expand.grid() instead of combn() just to avoid any mistakes with the ordering of the combinations.

ustates <- unique(measles$state)
StatePairs <- expand.grid(State1 = ustates, State2 = ustates)
StatePairs$Correlation <- apply(StatePairs, 1, ComputeCorr)

An alternative approach is the following, which takes advantage of the fact that cor() works on a data.frame or matrix, giving the pairwise correlation matrix.

## option 1: Use the fact that all state-year combinations are
## represented in a regular order. This would not work when the NA
## rows are removed altogether from the dataset, or even if the rows 
## are scrambled.

measlesMatrix1 <- matrix(

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@deepayan
Comment options

Answer selected by Excitedwanderer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants