Re: [R] Transformation of a data frame

From: hadley wickham <>
Date: Wed 13 Sep 2006 - 11:57:27 GMT

> one approach is to use reshape(), e.g.,
> # suppose that 'dat' is your data.frame, then
> res <- reshape(dat, direction = "wide", idvar = "Q", timevar = "S")
> res[] <- 0
> res

You can also use the reshape package:

datm <- melt(dat, id=1:2)
cast(datm, Q ~ S)

See the introduction to reshape
( for more details and examples.

Hadley mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Wed Sep 13 22:00:32 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 13 Sep 2006 - 12:30:05 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.