[R] Creating panel data
John Kane
jrkrideau at inbox.com
Mon Jul 23 19:06:22 CEST 2012
This looks really ugly but it 'may' do what you want. I was too lazy to generate enough raw data to check. Note i changed the names in x as they were a bit clumsy.
x <- data.frame( id = c(1,2), Event1= c(1,0), YEvent1 =
c(68.25,0), Event2 = c(0,1), YEvent2 = c(0,68.5))
y <- data.frame( id = c( rep (1,5), rep (2,5)), Year=c
(68.0,68.25,68.50,68.75,69.0))
y $ Event1 <- c (0,1,1,1,1,0,0,0,0,0)
y $ Event2 <- c (0,0,0,0,0,0,0,1,1,1)
x <- data.frame( id = c(1,2), Event1= c(1,0), YEvent1 =
c(68.25,0), Event2 = c(0,1), YEvent2 = c(0,68.5))
dd <- melt(x, id= c("id", "Event1", "Event2"),
value.name="year.quarter" )
dd1 <- subset(dd, dd[, 5] != 0 )
dd1 <- dd1[ , c(1,2,3,5)]
John Kane
Kingston ON Canada
> -----Original Message-----
> From: r at jp.pair.com
> Sent: Mon, 23 Jul 2012 11:33:37 -0500
> To: gunter.berton at gene.com
> Subject: Re: [R] Creating panel data
>
> At 10:38 AM 7/23/2012, you wrote:
> >You might also find it useful to use Hadley Wickham's plyr
> >and/or reshape2 packages, whose aim is to standardize and simplify
> >data manipulation tasks.
>>
> >Cheers,
> >Bert
>
>
> I have already used R enough to have correctly imported the actual
> data. After import, it is in the approximate format at the x
> dataframe I previously posted. I already found the plyr and reshape2
> packages and had assumed that the cast (or dcast) options might be
> the correct ones. Melt seemed to get me only what I already have. The
> examples I have seen thus far start with data in a various formats
> and end up in the format that I am starting with. In other words,
> they seem to do the exact opposite of what I'm trying to do. So I'm
> still stuck with how to get started and whether the functions in
> reshape2 are actually the correct ones to consider.
>
> ...still looking for some help on this.
>
> Jeff
>
> ______________________________________________
> 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.
____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
More information about the R-help
mailing list