Hello again,
Let say I have a matrix:
Mat - matrix(1:12, 4, 3)
And a vector:
Vec - 5:8
Now I want to do following:
Each element of row-i in 'Mat' will be divided by i-th element of Vec
Is there any direct way to doing that?
Thanks for your help
1 1.80
#[2,] 0.333 1 1.67
#[3,] 0.4285714 1 1.571429
#[4,] 0.500 1 1.50
A.K.
- Original Message -
From: Christofer Bogaso bogaso.christo...@gmail.com
To: r-help r-help@r-project.org
Cc:
Sent: Wednesday, April 17, 2013 8:39 AM
Subject: [R] On matrix
On 17-04-2013, at 14:39, Christofer Bogaso bogaso.christo...@gmail.com wrote:
Hello again,
Let say I have a matrix:
Mat - matrix(1:12, 4, 3)
And a vector:
Vec - 5:8
Now I want to do following:
Each element of row-i in 'Mat' will be divided by i-th element of Vec
Is there
On Wed, Mar 28, 2012 at 10:46:11PM +0200, Kehl Dániel wrote:
Dear list-members,
I have a 9-by-9 matrix lets call it A with first row a11, a12, a13,...,
a19 etc.
I also have a vector of length 3 (B).
I want to construct a matrix of size 3x3 in the following way:
- divide matrix A to 9 3x3
Dear David, Ted, Kjetil, Petr,
thank you, you guys did a great job, I'll use your ideas in the future
for sure.
After I sent the question I figured a way, see below.
x - 1:81
b - 1:3
Q - matrix(x,9,9)
result - matrix(matrix(colSums(matrix(t(Q),3)),,3,TRUE) %*% b,3,3)
I hope there is no error
On 29-03-2012, at 13:16, Kehl Dániel wrote:
Dear David, Ted, Kjetil, Petr,
thank you, you guys did a great job, I'll use your ideas in the future for
sure.
After I sent the question I figured a way, see below.
x - 1:81
b - 1:3
Q - matrix(x,9,9)
result -
On Thu, Mar 29, 2012 at 01:16:49PM +0200, Kehl Dániel wrote:
Dear David, Ted, Kjetil, Petr,
thank you, you guys did a great job, I'll use your ideas in the future
for sure.
After I sent the question I figured a way, see below.
x - 1:81
b - 1:3
Q - matrix(x,9,9)
result -
On Thu, Mar 29, 2012 at 03:13:25PM +0200, Petr Savicky wrote:
On Thu, Mar 29, 2012 at 01:16:49PM +0200, Kehl Dániel wrote:
Dear David, Ted, Kjetil, Petr,
thank you, you guys did a great job, I'll use your ideas in the future
for sure.
After I sent the question I figured a way, see
Dear list-members,
I have a 9-by-9 matrix lets call it A with first row a11, a12, a13,...,
a19 etc.
I also have a vector of length 3 (B).
I want to construct a matrix of size 3x3 in the following way:
- divide matrix A to 9 3x3 blocks
- first is
a11, a12, a13
a21, a22, a23
On 28-Mar-2012 Kehl Dániel wrote:
Dear list-members,
I have a 9-by-9 matrix lets call it A with first row
a11, a12, a13,..., a19 etc.
I also have a vector of length 3 (B).
I want to construct a matrix of size 3x3 in the following way:
- divide matrix A to 9 3x3 blocks
- first is
On Mar 28, 2012, at 4:46 PM, Kehl Dániel wrote:
Dear list-members,
I have a 9-by-9 matrix lets call it A with first row a11, a12,
a13,..., a19 etc.
I also have a vector of length 3 (B).
I want to construct a matrix of size 3x3 in the following way:
- divide matrix A to 9 3x3 blocks
- first
see inline.
On Wed, Mar 28, 2012 at 2:46 PM, Kehl Dániel ke...@ktk.pte.hu wrote:
Dear list-members,
I have a 9-by-9 matrix lets call it A with first row a11, a12, a13,..., a19
etc.
I also have a vector of length 3 (B).
I want to construct a matrix of size 3x3 in the following way:
- divide
I have suppose a matrix like that
mat - matrix(1:21, 7)
mat
[,1] [,2] [,3]
[1,]18 15
[2,]29 16
[3,]3 10 17
[4,]4 11 18
[5,]5 12 19
[6,]6 13 20
[7,]7 14 21
From this matrix, I want to create a vector like tha :
c(mat[7,],
On Aug 23, 2009, at 2:37 PM, Bogaso wrote:
I have suppose a matrix like that
mat - matrix(1:21, 7)
mat
[,1] [,2] [,3]
[1,]18 15
[2,]29 16
[3,]3 10 17
[4,]4 11 18
[5,]5 12 19
[6,]6 13 20
[7,]7 14 21
From this matrix, I want
No no, I actually want following result :
7, 14, 21, 6, 13, 20, 5, 12, 19,
David Winsemius wrote:
On Aug 23, 2009, at 2:37 PM, Bogaso wrote:
I have suppose a matrix like that
mat - matrix(1:21, 7)
mat
[,1] [,2] [,3]
[1,]18 15
[2,]2
Bogaso wrote:
No no, I actually want following result :
7, 14, 21, 6, 13, 20, 5, 12, 19,
c(t(mat[7:1,])) then.
David Winsemius wrote:
On Aug 23, 2009, at 2:37 PM, Bogaso wrote:
I have suppose a matrix like that
mat - matrix(1:21, 7)
mat
[,1] [,2] [,3]
On Sun, Aug 23, 2009 at 8:53 PM, Bogasobogaso.christo...@gmail.com wrote:
No no, I actually want following result :
7, 14, 21, 6, 13, 20, 5, 12, 19,
How about this?
x = c()
for (i in 7:1) x = c(x,mat[i,])
Guess that would do the trick.
Best,
Michael
--
Michael
On Aug 23, 2009, at 2:53 PM, Bogaso wrote:
No no, I actually want following result :
7, 14, 21, 6, 13, 20, 5, 12, 19,
Ooops. That is what I thought you wanted, but I didn't check very
carefully, did I?
c(apply(mat[7:1,],1,I) )
# the I() function just returns
The problem with David's proposal is revealed by:
mat[7:1,]
# [,1] [,2] [,3]
# [1,]7 14 21
# [2,]6 13 20
# [3,]5 12 19
# [4,]4 11 18
# [5,]3 10 17
# [6,]29 16
# [7,]18 15
which simply reverses the rows. Then:
There is another matrix strategy that succeeds, although it is
clearly less economical that the transpose approach:
matrix(mat[7:1, ], ncol=nrow(mat), byrow=TRUE) # will transpose the
matrix
I offer this only as a reminder that the byrow= parameter is available
when appropriate.
--
as.vector(t(mat[7:1,]))
On Aug 23, 2009, at 9:35 PM, David Winsemius wrote:
There is another matrix strategy that succeeds, although it is
clearly less economical that the transpose approach:
matrix(mat[7:1, ], ncol=nrow(mat), byrow=TRUE) # will transpose
the matrix
I offer this only
21 matches
Mail list logo