[R] melting a list: basic question

Dieter Menne dieter.menne at menne-biomed.de
Fri Jul 25 17:35:21 CEST 2008


baptiste auguie <ba208 <at> exeter.ac.uk> writes:

> 
> I'm trying to use the reshape package to perform a merging operation  
> on a list of data.frames as illustrated below,
> 
> > a <- 1:10
> > example <- list( data.frame(a=a, b=sin(a)),  data.frame(a=a,  
> > b=cos(a)) )
> >
> > melt(example, id = a)
> 
> this produces the desired result, where the data.frames have been  
> coerced into one with a common identifier variable "a". However, it  
> seems that if "a" is of mode numeric it is not recognized as an id  
> variable,
> 
> > a <- as.numeric(1:10)
> >
> > example <- list(data.frame(a=a, b=sin(a)), data.frame(a=a, b=cos(a)))
> >
> > melt(example, id = a) # this does not use a as an id variable
> 

This is the documented behavior: Only integers and factors are used for
grouping, but as.numeric is double, even if 1:10 looks like integers

a <- as.integer(1:10)
or simply

a <- 1:10

Dieter



More information about the R-help mailing list