[R] reshaping data

Henrique Dallazuanna wwwhsd at gmail.com
Tue Nov 24 19:27:32 CET 2009


Try this;

with(x, data.frame(Case = rep(Case, (Endyear - Startyear) + 1),
                           Year = unlist(mapply(seq, Startyear, Endyear))))

On Tue, Nov 24, 2009 at 4:14 PM, Joseph Magagnoli <jcm331 at gmail.com> wrote:
> Hi all,
> I have a dataframe that has one observation per case.
> for example:
>
> Case    Startyear      Endyear
>   A           1979              1989
>   B           1950              1955
>
> I would like to create a dataframe in which each case has
> multiple observations corresponding to the start and end year
> for example
>
> Case     Year
>  A          1979
>  A          1980
>  A           1981
> .                   .
> .                   .
> .                   .
>  A            1989
>  B            1950
>  B             1951
> and so on
>
>
>
> any help would be greatly appreciated.
>
> Joe
>
>        [[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