Re: [R] Regrouping data

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Thu, 07 Apr 2011 14:05:43 -0300

Try this:

1)
xtabs(values ~ name + period + cy_date, rat_dat)

2)
as.Date(rat_dat$cy_date, '%d-%b-%y') - as.Date(rat_dat$period, '%d-%b-%y')

On Thu, Apr 7, 2011 at 9:03 AM, Sandeepa Ramakrishnan <sandeepa_ramakrishnan_at_yahoo.com> wrote:
>
>
>
>
>
>
>
>
>
> Dear R forum
>
> I have just started my venture with R. While I am trying to learn R through the tutorials, I think the current problem I need to address to is beyond my knowledge about R.

>
> I have a dataframe as defined below -
>
>
> rat_dat = data.frame(name = c("A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D", "D"),
>                               period = c("31-Mar-11", "30-Mar-11", "29-Mar-11", "31-Mar-11", "30-Mar-11", "29-Mar-11",  "31-Mar-11", "30-Mar-11", "29-Mar-11", "31-Mar-11", "30-Mar-11", "29-Mar-11"),
> cy_date = c("31-May-11","31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11"),
> values = c(10.42, 10.46, 10.37, 12.62, 12.65, 12.61, 14.10, 14.12, 14.08, 11.11, 11.15, 11.17))
>
>
>> rat_dat
>    name    period   cy_date values
> 1     A 31-Mar-11 31-May-11  10.42
> 2     A 30-Mar-11 31-May-11  10.46
> 3     A 29-Mar-11 31-May-11  10.37
> 4     B 31-Mar-11 31-May-11  12.62
> 5     B 30-Mar-11 31-May-11  12.65
> 6     B 29-Mar-11 31-May-11  12.61
> 7     C 31-Mar-11 31-May-11  14.10
> 8     C 30-Mar-11 31-May-11  14.12
> 9     C 29-Mar-11 31-May-11  14.08
> 10    D 31-Mar-11 31-May-11  11.11
> 11    D 30-Mar-11 31-May-11  11.15
> 12    D 29-Mar-11 31-May-11  11.17
>
> My actual data is too large. I need to
>
> (1) rearrange this input as
>
>
>
>
>
>
>
>
>
> period
>   cy_date
>           A
>       B
>     C
>     D
>
> 31-Mar-11
>  31-May-11
> 10.42
>   12.62
> 14.10
> 11.11
>
> 30-Mar-11
>  31-May-11
> 10.46
>   12.65
> 14.12
> 11.15
>
> 29-Mar-11
>  31-May-11
> 10.37
>   12.61
> 14.08
> 11.17
>
> (2) Also, I need to find the difference between (rat_dat$cy_date) - (rat_dat$period)

>
> I hope I am able to put forward my requirement properly. If not, please forgive me.

>
> Sandeepa
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help_at_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.
>
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
R-help_at_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.
Received on Thu 07 Apr 2011 - 17:08:03 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Apr 2011 - 18:00:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive