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))))
r rstudio combinations heatmap
add a comment |
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))))
r rstudio combinations heatmap
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
add a comment |
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))))
r rstudio combinations heatmap
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
r rstudio combinations heatmap
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
add a comment |
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
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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