[R] how to melt variable to one variable
smartpink111 at yahoo.com
Sat Nov 23 23:07:07 CET 2013
I am not getting any errors.
data_chir <- read.table(text="N1_re N2_re N3_re
yes no no
no yes no
na yes yes
no na no",sep="",header=TRUE,stringsAsFactors=FALSE,na.strings="na")
melt(data_chir, measure.vars=c("N1_re", "N2_re"), var="zpd")
N3_re zpd value
1 no N1_re yes
2 no N1_re no
3 yes N1_re <NA>
4 no N1_re no
5 no N2_re no
6 no N2_re yes
7 yes N2_re yes
8 no N2_re <NA>
On Saturday, November 23, 2013 5:02 PM, maggy yan <kiotoqq at gmail.com> wrote:
sorry, I forgot that.. the variables look like this:
N1_re N2_re N3_re
yes no no
no yes no
na ye yes
no na no
2013/11/23 arun <smartpink111 at yahoo.com>
>You need to make a reproducible example for others to understand the error.
> data_chir <- data.frame(N1_re=sample(c(NA,"yes","no"),100,replace=TRUE),N2_re=sample(c(NA,"yes","no"),100,replace=TRUE),stringsAsFactors=FALSE)
> melt(data_chir, measure.vars=c("N1_re", "N2_re"), var="zpd") #no errors here.
>On Saturday, November 23, 2013 10:07 AM, maggy yan <kiotoqq at gmail.com> wrote:
>I want to make a stacked bar plot with one bar for two variables from my
>data "chir", the two variables have about 100 values like no, yes and na. I
>want to show how many no, yes and na they both have together with the
>stacked bar. I tried to melt these to variables first like this:
>melt1=melt(data_chir, measure.vars=c("N1_re", "N2_re"), var="zpd")
>but it says " arguments imply differing number of rows: 98, 196"
>maybe there is another way to make the plot without melt?
>thanks in advance!
> [[alternative HTML version deleted]]
>R-help at r-project.org mailing list
>PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help