Santosh | 16 May 2012 05:18
Picon

Splus equivalent of reshape in R

Hello R/Splus users..
I am posting in R discussion group in hope of wider response compared to
what I received from Splus user groups....

Was wondering if there is any function available in Splus 8.2 that is
equivalent to "reshape" of R?

Below is a sample dataset. Size [both rows and columns) of the dataset may
vary
X1        Y1    Y2    Y3
0.25    40    38    22
0.5        44    41    43
1        32    32    58
2        25  25    25
4        23    26    17
6        10    11    23
8        10 92 13
24        1.7 15 4.6

and I would like to have them stacked.... as shown below..
id    x    y
1    0.25    40
1    0.5    44
1    1    32
1    2    25
1    4    23
1    6    10
1    8    10
1    24    1.7
2    0.25 38
(Continue reading)

David Winsemius | 16 May 2012 05:33
Picon

Re: Splus equivalent of reshape in R


On May 15, 2012, at 11:18 PM, Santosh wrote:

> Hello R/Splus users..
> I am posting in R discussion group in hope of wider response  
> compared to
> what I received from Splus user groups....
>
> Was wondering if there is any function available in Splus 8.2 that is
> equivalent to "reshape" of R?
>
> Below is a sample dataset. Size [both rows and columns) of the  
> dataset may
> vary
> X1        Y1    Y2    Y3
> 0.25    40    38    22
> 0.5        44    41    43
> 1        32    32    58
> 2        25  25    25
> 4        23    26    17
> 6        10    11    23
> 8        10 92 13
> 24        1.7 15 4.6

data.frame(id=rep(1:(length(dfrm)-1), each=NROW(dfrm)),
             x= rep(dfrm[["X1"]], times= length(dfrm)-1),
             y=unlist(dfrm[-1]) )

You could also just copy the code for reshape or stack and see if it  
succeeds. the code for stack.data.frame has some preparatory steps but  
(Continue reading)

Jim Lemon | 16 May 2012 13:53
Picon
Gravatar

Re: Splus equivalent of reshape in R

On 05/16/2012 01:18 PM, Santosh wrote:
> Hello R/Splus users..
> I am posting in R discussion group in hope of wider response compared to
> what I received from Splus user groups....
>
> Was wondering if there is any function available in Splus 8.2 that is
> equivalent to "reshape" of R?
>
> Below is a sample dataset. Size [both rows and columns) of the dataset may
> vary...

Hi Santosh,
You may be able to use the code in the function rep_n_stack in the 
prettyR package in S-PLUS. It does what you want, and since it is 
written in R source code, it may run in S-PLUS. Just extract the code 
and "source" it into S-PLUS.

Jim


Gmane