I feel really basic, but I cannot figure out how to do it.
For certain formulas I need to multiply each element of a matrix (I know this can be done by using .) But I also need to be able to specify whether to use only columns or rows of a matrix.
So sometimes I need a[i,j], sometimes I need a[i,] and sometimes a[,j]. I thought I could use ' but this flips the matrix diagonally (Its The conjugate transposition operator) and I am not confident that this is what I need to use.
In R the code is
F.function = function(i,j,a, B, q, Th){
num = a[i,j] * B[j]^q
den = 1 + sum(Th[,j]*a[,j]*B^q)
return(num/den)
}
Do you mean a[i, :] and a[:, j]?
1 Like
it may also help to notice that a[i,:] is a flat vector, while a[i:i,:] is a 1xn array
1 Like
Ah… you see, I thought there must be a very obvious answer that I was over looking. Thank you!
I do not see how one is a flat vector and the other an array. I understand a[i:i,:] as being from the first to last instance of i (which would be useful if one wanted to specify certain rows/columns)? Where as I understand a[i,:] as specifying the whole row. Is this incorrect?
a[i,:]and a[i:i,:] contain the same elements, they just have different “forms”: the first is a vector, the other a 1xn matrix. This distinction is sometimes useful. If not, go for the vector version.
2 Likes