[R] Help with matrix

From: Van Wyk, Jaap <jaapvw_at_uj.ac.za>
Date: Sat, 26 Jul 2008 05:30:50 +0200


Hi
I have 3 vectors, say g1, g2 and f, where g1 and g2 contain the row and column indices of a matrix, with corresponding elements in f. How can I create a matrix containing the values in f ? For example:
g1 g2 f
3 4 10
2 1 30
4 4 50
How can then get a matrix that looks as follows:  0 0 0 0
30 0 0 0
 0 0 0 10
 0 0 0 50  

I am still learning R. I think reshape will help, but it is not clear how that works here.  

Any help is much appreciated.
Thank you.
Jacob    

Jacob L van Wyk
Department of Statistics
University of Johannesburg, APK
Box 524
Auckland Park 2006
South Africa
Office Tel: +27 11 559 3080
Fax: +27 11 559 2832  

        [[alternative HTML version deleted]]



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 Sat 26 Jul 2008 - 03:33:24 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 Sat 26 Jul 2008 - 04:32:28 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