s-news
[Top] [All Lists]

Re: Matrix minus A Vector

To: <s-news@lists.biostat.wustl.edu>
Subject: Re: Matrix minus A Vector
From: "Chen,Sichong" <sichong.chen@postgrad.manchester.ac.uk>
Date: Fri, 27 Oct 2006 06:07:13 +0800
In-reply-to: <20061026200404.339B413731F@mailgate.biostat.wustl.edu>
Thread-index: Acb5Odr5iWh7IazES3CjSdy2ytlpnQAESIPA
Hi,

Thank all. I have several replies. I summarize here.

The sweep function is quite good. The margin should be 2, for column
calculation.

Or create a new matrix.

A=matrix(0,nrow=5,ncol=3)     ## Or make A the matrix you have
B=matrix(c(2,4,3),ncol=ncol(A),nrow=nrow(A),byrow=T)

B
A-B

Regards,

CSC
SPlus 7.0 & FinMetrics 2.0 User
Windows XP

-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Chen,Sichong
Sent: Friday, October 27, 2006 4:04 AM
To: s-news@lists.biostat.wustl.edu
Subject: [S] Matrix minus A Vector

Dear Users

I have a matrix (4x3)
4       5       6       
2       4       5       
2       4       6       
6       5       5       
3       8       9       

And a vector   (1x3)
2       4       3       

I would like to use the first column of the matrix minus the first number of
the vector "2", then the second column of the matrix minus the second number
of the vector "4" and so on.

The final result of a matrix is supposed to be:
2       1       3       
0       0       2       
0       0       3       
4       1       2       
1       4       6       

I know the stupid way is to calculate one column by one column, but I think
there must be some quicker and smarter way to do it.

Many thanks,
Regards,
Sichong
SPlus 7.0 & FinMetrics 2.0 User
Windows XP


Sichong Chen
PhD of Finance
Manchester Business School
University of Manchester
Oxford Road
Manchester
United Kingdom
M13 9PL 


-----Original Message-----
From: s-news-owner@lists.biostat.wustl.edu
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Chen,Sichong
Sent: Friday, October 27, 2006 4:04 AM
To: s-news@lists.biostat.wustl.edu
Subject: [S] Matrix minus A Vector

Dear Users

I have a matrix (4x3)
4       5       6       
2       4       5       
2       4       6       
6       5       5       
3       8       9       

And a vector   (1x3)
2       4       3       

I would like to use the first column of the matrix minus the first number of
the vector "2", then the second column of the matrix minus the second number
of the vector "4" and so on.

The final result of a matrix is supposed to be:
2       1       3       
0       0       2       
0       0       3       
4       1       2       
1       4       6       

I know the stupid way is to calculate one column by one column, but I think
there must be some quicker and smarter way to do it.

Many thanks,
Regards,
Sichong
SPlus 7.0 & FinMetrics 2.0 User
Windows XP



--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news



<Prev in Thread] Current Thread [Next in Thread>