Subtracting matrices with different arguments

Asked

Viewed 97 times

4

We can subtract two matrices (or two vectors) that were written with different commands?

Example:

x<-array(1:4,c(4,1,1))
y<-cbind(c(1:4))
x-y
"Error> non-conformable objects"

This means that both vectors have to use the same commands?

2 answers

1

Your object x has dimensions 4x1x1 and the object y only 4x1, you can not subtract objects with different dimensions.

If you put the dimensions 4x1 in x works:

x<-array(1:4,c(4,1))
y<-cbind(c(1:4))
x-y
     [,1]
[1,]    0
[2,]    0
[3,]    0
[4,]    0

0

no; it just means that x and yare objects of different dimensions. for example,

      x<-array(1:4,dim=c(4))
      y = 1:4
      x-y
      [1] 0 0 0 0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.