Graphics Reference
In-Depth Information
Some data sets don't come with a column with an ID variable. For example, in the corneas data
set, each row represents one pair of measurements, but there is no ID variable. Without an ID
variable, you won't be able to tell how the values are meant to be paired together. In these cases,
you can add an ID variable before using melt() :
# Make a copy of the data
co <- corneas
co
affected notaffected
488
484
478
478
480
492
426
444
440
436
410
398
458
464
460
476
# Add an ID column
co$id <- 1 :nrow(co)
melt(co, id.vars = "id" , variable.name = "eye" , value.name = "thickness" )
id eye thickness
1
affected
488
2
affected
478
3
affected
480
4
affected
426
5
affected
440
6
affected
410
7
affected
458
8
affected
460
1 notaffected
484
2 notaffected
478
3 notaffected
492
4 notaffected
444
5 notaffected
436
6 notaffected
398
7 notaffected
464
8 notaffected
476
Having numeric values for the ID variable may be problematic for subsequent analyses, so you
may want to convert id to a character vector with as.character() , or a factor with factor() .
Search WWH ::




Custom Search