Re: [R] melting a list: basic question

2008-07-27 Thread hadley wickham
> Is it possible to install your development version of reshape? I could not
> find it alongside of ggplot2 on github.

Not yet, but I'm working on it.

> If not, I've added "..." in the
> method for the current version and it seems to work for me.

Yes, that's the exact change I made.

Thanks!

Hadley

-- 
http://had.co.nz/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] melting a list: basic question

2008-07-26 Thread baptiste auguie



On 26 Jul 2008, at 02:52, hadley wickham wrote:

On Fri, Jul 25, 2008 at 8:50 PM, hadley wickham  
<[EMAIL PROTECTED]> wrote:
On Fri, Jul 25, 2008 at 9:49 AM, baptiste auguie  
<[EMAIL PROTECTED]> wrote:

Dear list,


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)


You want:

melt(example, id = "a")

i.e. the id argument is a character or numeric vector specifying  
which

variables to use as id variables.  Your call would be equivalent to

melt(example, id = 1:10)

which clearly is incorrect for your example.



Sorry about the poor example, I hadn't realized it worked only thanks  
to the default behavior.




I've just noticed that there's also a bug in the released version
(fixed in my development version) which means that the id argument to
melt.list() is not being passed on to the individual
melt.data.frame()s



Considering the following example, this makes sense:


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

melt(example[[1]], id = "a") # the method for the individual  
data.frame works fine


Is it possible to install your development version of reshape? I could  
not find it alongside of ggplot2 on github. If not, I've added "..."  
in the method for the current version and it seems to work for me.



melt.list <- function(data, ..., level=1) {
var <- nulldefault(attr(data, "varname"), paste("L", level, sep=""))
names <- nulldefault(names(data), 1:length(data))
parts <- lapply(data, melt, level=level+1, ...)

namedparts <- mapply(function(x, name) {
 x[[var]] <- name
 x
}, parts, names, SIMPLIFY=FALSE)
do.call(rbind.fill, namedparts)
}


Many thanks,

baptiste

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] melting a list: basic question

2008-07-25 Thread hadley wickham
On Fri, Jul 25, 2008 at 8:50 PM, hadley wickham <[EMAIL PROTECTED]> wrote:
> On Fri, Jul 25, 2008 at 9:49 AM, baptiste auguie <[EMAIL PROTECTED]> wrote:
>> Dear list,
>>
>>
>> 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)
>
> You want:
>
> melt(example, id = "a")
>
> i.e. the id argument is a character or numeric vector specifying which
> variables to use as id variables.  Your call would be equivalent to
>
> melt(example, id = 1:10)
>
> which clearly is incorrect for your example.

I've just noticed that there's also a bug in the released version
(fixed in my development version) which means that the id argument to
melt.list() is not being passed on to the individual
melt.data.frame()s

Hadley

-- 
http://had.co.nz/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] melting a list: basic question

2008-07-25 Thread hadley wickham
On Fri, Jul 25, 2008 at 9:49 AM, baptiste auguie <[EMAIL PROTECTED]> wrote:
> Dear list,
>
>
> 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)

You want:

melt(example, id = "a")

i.e. the id argument is a character or numeric vector specifying which
variables to use as id variables.  Your call would be equivalent to

melt(example, id = 1:10)

which clearly is incorrect for your example.

Hadley

-- 
http://had.co.nz/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] melting a list: basic question

2008-07-25 Thread baptiste auguie
Given that I cannot arbitrarily change the data to make "a" an  
integer, can I still use "a" as a grouping variable?


I tried melt(example, id = factor(a)) but it does not work either.  
Must this change from numeric values to factors be done before  
applying melt?


Thanks,

baptiste

On 25 Jul 2008, at 16:35, Dieter Menne wrote:





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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] melting a list: basic question

2008-07-25 Thread Dieter Menne
baptiste auguie  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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.