[R] Regrouping data

Henrique Dallazuanna wwwhsd at gmail.com
Thu Apr 7 19:05:43 CEST 2011


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



More information about the R-help mailing list