Re: [R] Make matrix from SQL query result

From: Jim Brennan <jfbrennan_at_rogers.com>
Date: Sat 25 Jun 2005 - 03:40:17 EST


You can use reshape which seems popular this week!

> rr

  equity_id     date returns
1         1 20050619    0.12
2         2 20050619    0.03
3         1 20050620   -0.01
4         2 20050620    0.01



> reshape(rr,timevar="equity_id",direction="wide",idvar="date")
date returns.1 returns.2 1 20050619 0.12 0.03 3 20050620 -0.01 0.01

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Gilbert Wu Sent: June 24, 2005 12:36 PM
To: r-help@stat.math.ethz.ch
Subject: [R] Make matrix from SQL query result

Hi,  

I am trying to form a matrix from a SQL query result.  

The SQL query result looks like this:  

equity_id         date              returns
1                 20050619          0.12
2                 20050619          0.03
1                 20050620          -0.01
2                 20050620          0.01
 

The target matrix looks like this:    

date                     1               2
20050619           0.12            0.03
20050620           -0.01           0.01
 

Any suggestion would be much appreciated.  

Many Thanks.  

Gilbert

        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jun 25 03:46:01 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:33:02 EST