The default behavior of melt.data.frame is to return the "variable" column in "factor" class. Here is an example:
> head(airquality)
ozone solar.r wind temp month day
1 41 190 7.4 67 5 1
2 36 118 8.0 72 5 2
3 12 149 12.6 74 5 3
4 18 313 11.5 62 5 4
5 NA NA 14.3 56 5 5
6 28 NA 14.9 66 5 6
> x = melt(head(airquality))
Using as id variables
> head(x)
variable value
1 ozone 41
2 ozone 36
3 ozone 12
4 ozone 18
5 ozone NA
6 ozone 28
> class(x$variable)
[1] "factor"
The question is that is there any parameter to change the class from factor to character? I tried options(stringsAsFactors = FALSE)
but it is not working.