This is very straightforward using the reshape2 package:
library('reshape2')
dc <- dcast(a, name ~ year, value_var = 'amount')
name 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
1a123456789 10 NA NA NA NA
2b 11 12
Thanks David and Bill. I don't know how I couldn't think of that - maybe
because I'm working through a brutal flu right now.
Thanks for the help. This list is a fantastic resource.
Trevor
On Fri, Nov 18, 2011 at 4:18 PM, David Winsemius wrote:
>
> On Nov 18, 2011, at 7:04 PM, Trevor Davies wr
On Nov 18, 2011, at 7:04 PM, Trevor Davies wrote:
A late friday afternoon coding question. I'm having a hard time
thinking
of the correct search terms for what I want to do.
If I have a df like this:
a <-
data.frame(name=c(rep('a',10),rep('b',
15)),year=c(1971:1980,1971:1985),amount=1:25)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf Of Trevor Davies
> Sent: Friday, November 18, 2011 4:05 PM
> To: r-help@r-project.org
> Subject: [R] reshape data.frame
>
> A late friday afternoon coding question.
A late friday afternoon coding question. I'm having a hard time thinking
of the correct search terms for what I want to do.
If I have a df like this:
a <-
data.frame(name=c(rep('a',10),rep('b',15)),year=c(1971:1980,1971:1985),amount=1:25)
name year amount
1 a 1971 1
2 a 1972
5 matches
Mail list logo