On 30.10.2011 04:51, Wendy wrote:
Hi,
I have a vector and a matrix. For example,
A = [
12
3
4];
B = [
4 13
10 2
4 8];
I am comparing A to each column of B using A>B[,ii], so the expected result
is
C = [
10
01
00];
This list is about R rather than Matlab dial
The recycling rule should apply here (see 'An Introduction to R', Sec.
5.4.1; and ?Comparison, under 'Value').
x <- -5:5
A <- cbind(x, x, x)
vec <- numeric(length(x))
A > vec ### recycling
apply(A,2,`>`,vec) ### using apply
vec <- numeric(11) + 3; vec[1] <- -6
A > vec
Hi,
To compare row wise is merely to compare column wise using the transpose matrix:
t(B) < A
or
t(t(B) wrote:
> Given that you want to compare
> columns, you can just do:
>
> A > B
>
> If you wanted to compare rows, then
> it is more troublesome. One approach
> would be:
>
> rep(A, each=nrow(
Given that you want to compare
columns, you can just do:
A > B
If you wanted to compare rows, then
it is more troublesome. One approach
would be:
rep(A, each=nrow(B)) > B
On 30/10/2011 03:51, Wendy wrote:
Hi,
I have a vector and a matrix. For example,
A = [
12
3
4];
B = [
4 13
10
Hi Wendy,
Most of the binary operators can deal with matrices and vectors natively:
A<-c(12,3,4)
B<-matrix(c(4,10,4,13,2,8),3,2)
B
[,1] [,2]
[1,]4 13
[2,] 102
[3,]48
B wrote:
> On 10/30/2011 02:51 PM, Wendy wrote:
>>
>> Hi,
>>
>> I have a vector and a matrix. For exampl
On 10/30/2011 02:51 PM, Wendy wrote:
Hi,
I have a vector and a matrix. For example,
A = [
12
3
4];
B = [
4 13
10 2
4 8];
I am comparing A to each column of B using A>B[,ii], so the expected result
is
C = [
10
01
00];
I am looking for a way to do this quickly ins
Hi,
I have a vector and a matrix. For example,
A = [
12
3
4];
B = [
4 13
10 2
4 8];
I am comparing A to each column of B using A>B[,ii], so the expected result
is
C = [
10
01
00];
I am looking for a way to do this quickly instead of going through the for
loop
7 matches
Mail list logo