[R] How to reformat data from database into data.frame?
Mark Dalphin
mdalphin at amgen.com
Wed Oct 22 21:05:44 CEST 2003
I'm trying to find a clever way to re-map data from a database
query into a data.frame.
Querying a database often returns a table (data.frame) like this:
GeneID MethodID Value
6 1 123
6 2 456
6 3 987
7 1 234
7 3 432
8 2 190
8 3 34
8 1 864
Note that GeneID=7 doesn't have a value for MethodID=2.
Note that GeneID=8 doesn't have the MethodID in any particular order
and, in fact, there doesn't need to be an order to the GeneID, although
I can force ordering as part of my SQL query.
I want to reformat this into a data.frame with multiple columns:
Value Value Value
GeneID Method1 Method2 Method3
6 123 456 987
7 234 NA 432
8 864 190 34
Is there an elegant way to do this type of reformating in R?
Thanks.
Mark
--
Mark Dalphin email: mdalphin at amgen.com
Mail Stop: 29-2-A phone: +1-805-447-4951 (work)
One Amgen Center Drive +1-805-375-0680 (home)
Thousand Oaks, CA 91320 fax: +1-805-499-9955 (work)
More information about the R-help
mailing list