Re: [R] Converting a data frame with values into a matrix/

From: hadley wickham <h.wickham_at_gmail.com>
Date: Wed, 12 Mar 2008 13:26:48 -0500

> mm1 <- cast(mm, Class~Name)
> aba <- mm1[,2:6]
> aba[is.na(aba)] <- 1
> final <- data.frame(mm1$Class, aba)
> names(final) <- names(mm1)
> final

You can abbreviate all this to:

final <- cast(mm, Class ~ Name, fill = 1)

Hadley

-- 
http://had.co.nz/

______________________________________________
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 Wed 12 Mar 2008 - 18:37:22 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 Wed 12 Mar 2008 - 19:30:22 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