Re: [R] Transposing by a group variable

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Thu, 14 Feb 2008 13:20:45 -0200

Try also:

reshape(cbind(d, time=unlist(sapply(table(d$group), seq))), idvar="group", direction="wide")

On 14/02/2008, Shubha Vishwanath Karanth <shubhak_at_ambaresearch.com> wrote:
> Hi R,
>
>
>
> Can I transpose a data frame by a particular group variable?
>
>
>
> For example:
>
> d=data.frame(group=c(1,1,2,2,2),val=c(6,4,6,3,5))
>
> And my output should be:
>
> data.frame(group=c(1,2),v1=c(6,6),v2=c(4,3),v3=c(NA,5))
>
>
>
> Many thanks,
>
> Shubha
>
> This e-mail may contain confidential and/or privileged i...{{dropped:13}}
>
> ______________________________________________
> 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 14 Feb 2008 - 15:26:23 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 14 Feb 2008 - 15:30:14 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