I have a dataframe that looks like this:
colnames<-c('Assay','Sample','Interference','0','24','48','168')
Assay<-c('1','2','3','4','5','6','7','8','9')
Sample<-c('S1.16S','B2','B5','B32','B36','B39','B47','B57','A15')
Interference<-c('N','Y','N','N','N','Y','N','Y','Y')
'0'<-c(14.337,24.21,14.97,15.51,14.64,28.83,13.63,21.08,20.26)
'24'<-c(NA,25.13,14.99,15.35,14.71,28.64,13.68,22.04,20.64)
'48'<-c(NA,25.32,15.00,15.97,14.64,28.69,13.87,NA,22.14)
'168'<-c(NA,24.7,15.09,17.31,14.67,NA,14.9,23.22,21.56)
d<-data.frame(Assay, Sample, Interference, 0,24,48,168, check.names=FALSE)
When using the reshape package to melt the data to long format, the values of columns 0, 24, 48, and 168 are changed to 1-4, like so:
library(reshape)
dlong<-melt(d, id.vars=c('Assay','Sample','Interference'), measure.vars=c('0','24','48','168'))
dlong$variable<-as.numeric(dlong$variable)
head(dlong)
# Assay Sample Interference variable value
#1 1 S1.16S N 1 0
#2 2 B2 Y 1 0
#3 3 B5 N 1 0
#4 4 B32 N 1 0
#5 5 B36 N 1 0
#6 6 B39 Y 1 0
How do I retain the numeric values as they are (0,24,48,168) in the column 'variable' without having to use additional code to convert them later? I need to run downstream correlation analyses on the full dataset, and this creates quite a lag in my processing time.