stack problem

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

stack problem

Gabor Grothendieck
stack() seems to drop empty levels.  Perhaps there could be a
drop=FALSE argument if one wanted all the original levels.  In the
example below, we may wish to retain level "b" in s$ind even though
component LL$b has length 0.

> LL <- list(a = 1:3, b = list())
> s <- stack(LL)
> str(s)
'data.frame':   3 obs. of  2 variables:
 $ values: int  1 2 3
 $ ind   : Factor w/ 1 level "a": 1 1 1


--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: stack problem

Michael Lawrence-3
I'll add the drop argument but I'm wondering about the order of the
levels. Should we set the levels to unique(names(x)) or sort them,
too?

On Mon, Jun 27, 2016 at 10:39 AM, Gabor Grothendieck
<[hidden email]> wrote:

> stack() seems to drop empty levels.  Perhaps there could be a
> drop=FALSE argument if one wanted all the original levels.  In the
> example below, we may wish to retain level "b" in s$ind even though
> component LL$b has length 0.
>
>> LL <- list(a = 1:3, b = list())
>> s <- stack(LL)
>> str(s)
> 'data.frame':   3 obs. of  2 variables:
>  $ values: int  1 2 3
>  $ ind   : Factor w/ 1 level "a": 1 1 1
>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: stack problem

Gabor Grothendieck
One would normally want the original order that so that one can stack
a list, operate on the result and then unstack it back with the
unstacked result having the same ordering as the original.

LL <- list(z = 1:3, a = list())
# since we can't do s <- stack(LL,. drop = FALSE) do this instead:
s <- transform(stack(LL), ind = factor(as.character(ind), levels = names(LL)))
unstack(s)




On Mon, Jun 27, 2016 at 2:55 PM, Michael Lawrence
<[hidden email]> wrote:

> I'll add the drop argument but I'm wondering about the order of the
> levels. Should we set the levels to unique(names(x)) or sort them,
> too?
>
> On Mon, Jun 27, 2016 at 10:39 AM, Gabor Grothendieck
> <[hidden email]> wrote:
>> stack() seems to drop empty levels.  Perhaps there could be a
>> drop=FALSE argument if one wanted all the original levels.  In the
>> example below, we may wish to retain level "b" in s$ind even though
>> component LL$b has length 0.
>>
>>> LL <- list(a = 1:3, b = list())
>>> s <- stack(LL)
>>> str(s)
>> 'data.frame':   3 obs. of  2 variables:
>>  $ values: int  1 2 3
>>  $ ind   : Factor w/ 1 level "a": 1 1 1
>>
>>
>> --
>> Statistics & Software Consulting
>> GKX Group, GKX Associates Inc.
>> tel: 1-877-GKX-GROUP
>> email: ggrothendieck at gmail.com
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>



--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: stack problem

Michael Lawrence-3
Agreed. Just putting that out there.

On Mon, Jun 27, 2016 at 12:49 PM, Gabor Grothendieck
<[hidden email]> wrote:

> One would normally want the original order that so that one can stack
> a list, operate on the result and then unstack it back with the
> unstacked result having the same ordering as the original.
>
> LL <- list(z = 1:3, a = list())
> # since we can't do s <- stack(LL,. drop = FALSE) do this instead:
> s <- transform(stack(LL), ind = factor(as.character(ind), levels = names(LL)))
> unstack(s)
>
>
>
>
> On Mon, Jun 27, 2016 at 2:55 PM, Michael Lawrence
> <[hidden email]> wrote:
>> I'll add the drop argument but I'm wondering about the order of the
>> levels. Should we set the levels to unique(names(x)) or sort them,
>> too?
>>
>> On Mon, Jun 27, 2016 at 10:39 AM, Gabor Grothendieck
>> <[hidden email]> wrote:
>>> stack() seems to drop empty levels.  Perhaps there could be a
>>> drop=FALSE argument if one wanted all the original levels.  In the
>>> example below, we may wish to retain level "b" in s$ind even though
>>> component LL$b has length 0.
>>>
>>>> LL <- list(a = 1:3, b = list())
>>>> s <- stack(LL)
>>>> str(s)
>>> 'data.frame':   3 obs. of  2 variables:
>>>  $ values: int  1 2 3
>>>  $ ind   : Factor w/ 1 level "a": 1 1 1
>>>
>>>
>>> --
>>> Statistics & Software Consulting
>>> GKX Group, GKX Associates Inc.
>>> tel: 1-877-GKX-GROUP
>>> email: ggrothendieck at gmail.com
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>
>
>
> --
> Statistics & Software Consulting
> GKX Group, GKX Associates Inc.
> tel: 1-877-GKX-GROUP
> email: ggrothendieck at gmail.com
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel