Graphics Reference
In-Depth Information
The measure variables are by default all the non-ID variables. The names of these variables are
put into a new column specified by
variable.name
, and the values are put into a new column
specified by
value.name
.
If you don't want to use all the non-ID columns as measure variables, you can specify
meas-
ure.vars
. For example, in the
drunk
data set, we can use just the
0-29
and
30-39
groups:
drunk
sex
0
-
29 30
-
39 40
-
49 50
-
59 60
+
male
185
207
260
180 71
female
4
13
10
7 10
melt(drunk, id.vars
=
"sex"
, measure.vars
=
c(
"0-29"
,
"30-39"
),
variable.name
=
"age"
, value.name
=
"count"
)
sex age count
male
0
-
29
185
female
0
-
29
4
male
30
-
39
207
female
30
-
39
13
It's also possible to use more than one column as the ID variables:
plum_wide
length time dead alive
long at_once
84
156
long in_spring
156
84
short at_once
133
107
short in_spring
209
31
melt(plum_wide, id.vars
=
c(
"length"
,
"time"
), variable.name
=
"survival"
,
value.name
=
"count"
)
length time survival count
long at_once dead
84
long in_spring dead
156
short at_once dead
133
short in_spring dead
209
long at_once alive
156
long in_spring alive
84
short at_once alive
107
short in_spring alive
31