I have: data (questionnaire) of five variables (V1 through V5), each answered on a scale from 1 to 6.
I'd like to calculate the following correlations: Take V1 as condition, and for each possible V1 value calculate the correlation of (V2 + V3) with (V4 plus V5). In effect: look only at cases where V1 = 1 and calculate cor of V2+V3 with V4+V5; then for V1 = 2 and so on.
I'd like to write it in a loop, but can't get it to work. I think it would be possible to manually add columns containing the sums and then sort the data with dplyr package, but that seems very clumsy.
**Example Data**
ID V1 V2 V3 V4 V5
61617 3 4 2 2 3
61618 3 3 3 5 5
61620 4 5 4 2 3
61621 2 5 2 4 1
61622 2 3 4 4 3
61623 3 5 2 2 3
61624 1 2 2 1 1
Even to start with, I've manually tried the unconditional correlation of sums cor(sum(V$V2,V$V3),sum(V$V4,V$V5),use="pairwise.complete"), which yielded NA, too.
I've tried ifelse and rowSums statements, but to no avail. How can I approach this as a non-programmer?