Jagz,

Assuming that your data frame is called df, try this ...

tapply(df$Value, list(df$ID1, df$ID2), mean)

Jean


`·.,,  ><(((º>   `·.,,  ><(((º>   `·.,,  ><(((º>

Jean V. Adams
Statistician
U.S. Geological Survey
Great Lakes Science Center
223 East Steinfest Road
Antigo, WI 54409  USA
715-627-4317, ext. 3125  (Office)
715-216-8014  (Cell)
715-623-6773  (FAX)
http://www.glsc.usgs.gov  (GLSC web site)
http://profile.usgs.gov/jvadams  (My homepage)
jvadams@usgs.gov  (E-mail)




From:
Jagz Bell <jagzbell@yahoo.com>
To:
"r-help@R-project.org" <r-help@r-project.org>
Date:
08/02/2011 12:13 PM
Subject:
[R] Data frame to matrix  - revisited
Sent by:
r-help-bounces@r-project.org



Hi,
I've tried to look through all the previous related Threads/posts but 
can't find a solution to what's probably a simple question.
 
I have a data frame comprised of three columns e.g.:
 
ID1 ID2 Value
a b 1
b d 1
c a 2
c e 1
d a 1
e d 2
 
I'd like to convert the data to a matrix i.e.:
 
 a b c d e
a n/a 1 2 1 n/a
b 1 n/a n/a 1 n/a 
c 2 n/a n/a n/a 1
d 1 1 n/a n/a 2
e n/a n/a 1 2 n/a
 
Any help is much appreciated,
 
Jagz

______________________________________________
R-help@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.



	[[alternative HTML version deleted]]

