R combination of variables in heatmap











up vote
-3
down vote

favorite












I have the following data 1 (excerpt) which I collected in interviews. 1 means the interviewee was affirmative, 0 means not, NA means no answer. Now I want to know for every pairwise combination of variables (R-Skills, C++-Skills, LikesPoetry) the number of affirmative answers in both categories like in this table 2. And lastly, I want to have that table 2 plotted as a heat map in R.



In order to create that table 2 I tried count() from plyr which gives me the frequency when I pass on the combinations in a vector. However, my original table has many more variables.



library(plyr)
count(dta, vars = c("R.Skills", "C...Skills"))

R.Skills C...Skills freq
1 0 0 1
2 1 1 2
3 NA 1 1


Thank you for your help!



Edit: I found a solution. However, a quite complicated one. If you have a more elegant solution please let me know.



I generate the total of each column and put it together into a data frame



rbind(t(cbind(colSums(dta[dta$C...Skills==1,], na.rm = TRUE)))
,t(cbind(colSums(dta[dta$R.Skills==1,], na.rm = TRUE))))










share|improve this question
























  • what have you tried so far? please provide a minimal, complete, and verifiable example
    – landru27
    Nov 11 at 19:55










  • @landru27: I edited the original post.
    – user7015
    Nov 11 at 20:27










  • Use dput() to provide us with a sample dataset that we can work with.
    – wl1234
    Nov 11 at 23:21















up vote
-3
down vote

favorite












I have the following data 1 (excerpt) which I collected in interviews. 1 means the interviewee was affirmative, 0 means not, NA means no answer. Now I want to know for every pairwise combination of variables (R-Skills, C++-Skills, LikesPoetry) the number of affirmative answers in both categories like in this table 2. And lastly, I want to have that table 2 plotted as a heat map in R.



In order to create that table 2 I tried count() from plyr which gives me the frequency when I pass on the combinations in a vector. However, my original table has many more variables.



library(plyr)
count(dta, vars = c("R.Skills", "C...Skills"))

R.Skills C...Skills freq
1 0 0 1
2 1 1 2
3 NA 1 1


Thank you for your help!



Edit: I found a solution. However, a quite complicated one. If you have a more elegant solution please let me know.



I generate the total of each column and put it together into a data frame



rbind(t(cbind(colSums(dta[dta$C...Skills==1,], na.rm = TRUE)))
,t(cbind(colSums(dta[dta$R.Skills==1,], na.rm = TRUE))))










share|improve this question
























  • what have you tried so far? please provide a minimal, complete, and verifiable example
    – landru27
    Nov 11 at 19:55










  • @landru27: I edited the original post.
    – user7015
    Nov 11 at 20:27










  • Use dput() to provide us with a sample dataset that we can work with.
    – wl1234
    Nov 11 at 23:21













up vote
-3
down vote

favorite









up vote
-3
down vote

favorite











I have the following data 1 (excerpt) which I collected in interviews. 1 means the interviewee was affirmative, 0 means not, NA means no answer. Now I want to know for every pairwise combination of variables (R-Skills, C++-Skills, LikesPoetry) the number of affirmative answers in both categories like in this table 2. And lastly, I want to have that table 2 plotted as a heat map in R.



In order to create that table 2 I tried count() from plyr which gives me the frequency when I pass on the combinations in a vector. However, my original table has many more variables.



library(plyr)
count(dta, vars = c("R.Skills", "C...Skills"))

R.Skills C...Skills freq
1 0 0 1
2 1 1 2
3 NA 1 1


Thank you for your help!



Edit: I found a solution. However, a quite complicated one. If you have a more elegant solution please let me know.



I generate the total of each column and put it together into a data frame



rbind(t(cbind(colSums(dta[dta$C...Skills==1,], na.rm = TRUE)))
,t(cbind(colSums(dta[dta$R.Skills==1,], na.rm = TRUE))))










share|improve this question















I have the following data 1 (excerpt) which I collected in interviews. 1 means the interviewee was affirmative, 0 means not, NA means no answer. Now I want to know for every pairwise combination of variables (R-Skills, C++-Skills, LikesPoetry) the number of affirmative answers in both categories like in this table 2. And lastly, I want to have that table 2 plotted as a heat map in R.



In order to create that table 2 I tried count() from plyr which gives me the frequency when I pass on the combinations in a vector. However, my original table has many more variables.



library(plyr)
count(dta, vars = c("R.Skills", "C...Skills"))

R.Skills C...Skills freq
1 0 0 1
2 1 1 2
3 NA 1 1


Thank you for your help!



Edit: I found a solution. However, a quite complicated one. If you have a more elegant solution please let me know.



I generate the total of each column and put it together into a data frame



rbind(t(cbind(colSums(dta[dta$C...Skills==1,], na.rm = TRUE)))
,t(cbind(colSums(dta[dta$R.Skills==1,], na.rm = TRUE))))







r rstudio combinations heatmap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 at 22:47

























asked Nov 11 at 19:34









user7015

12




12












  • what have you tried so far? please provide a minimal, complete, and verifiable example
    – landru27
    Nov 11 at 19:55










  • @landru27: I edited the original post.
    – user7015
    Nov 11 at 20:27










  • Use dput() to provide us with a sample dataset that we can work with.
    – wl1234
    Nov 11 at 23:21


















  • what have you tried so far? please provide a minimal, complete, and verifiable example
    – landru27
    Nov 11 at 19:55










  • @landru27: I edited the original post.
    – user7015
    Nov 11 at 20:27










  • Use dput() to provide us with a sample dataset that we can work with.
    – wl1234
    Nov 11 at 23:21
















what have you tried so far? please provide a minimal, complete, and verifiable example
– landru27
Nov 11 at 19:55




what have you tried so far? please provide a minimal, complete, and verifiable example
– landru27
Nov 11 at 19:55












@landru27: I edited the original post.
– user7015
Nov 11 at 20:27




@landru27: I edited the original post.
– user7015
Nov 11 at 20:27












Use dput() to provide us with a sample dataset that we can work with.
– wl1234
Nov 11 at 23:21




Use dput() to provide us with a sample dataset that we can work with.
– wl1234
Nov 11 at 23:21

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252430%2fr-combination-of-variables-in-heatmap%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252430%2fr-combination-of-variables-in-heatmap%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Bressuire

Vorschmack

Quarantine