A<-X*Xt
#Error pops up
Error in X * Xt : non-conformable arrays
#OR
A<-crossprod(X,Xt)
#error pops up
Error in base::crossprod(x, y) : non-conformable arguments
#Even dimensions of matrices are:-
dim(Xt)
[1] 3 47
dim(X)
[1] 47 3
Why matrices are not multiplying even when their order satisfies the matrices product condition
(m X n) * (n X p) resulting matrix will have order (m X p)
If A and B are matrices, A*B tries to perform elementwise multiplication, which is possible only if they are of same dimensions, which is not the case here.
To multiply two matrices, use %*% operator. You can also use crossprod or tcrossprod, but then you don't need to take transpose previously. Here's what the documentation of crossprod says:
Given matrices x and y as arguments, return a matrix cross-product. This is formally equivalent to (but usually slightly faster than) the call t(x) %% y (crossprod) or x %% t(y) (tcrossprod).
Also, you can't fit 100 elements in a 47 \times 1 matrix, and since you have only 1 column, byrow argument is not required.
# setting seed
set.seed(seed = 23660)
# matrix 1
X <- matrix(data = rnorm(n = 47),
nrow = 47)
X <- cbind(X,
rnorm(n = 47),
1)
# matrix 2: transpose of matrix 1
X_t <- t(x = X)
# matrix multiplication
a <- X %*% X_t
b <- crossprod(x = X_t)
c <- tcrossprod(x = X)
# checking their equality
all.equal(a, b, c)
#> [1] TRUE