Does the c command create a row vector or a column vector by default in R -


in r, when use command this:

b <-c(7,10) b 

does create row vector (1 row, 2 cols) or column vector (1 col, 2 rows) default?

i can't tell displayed output. r beginner (as obvious :))

neither. vector not have dimension attribute default, has length.

if @ documentation on matrix arithmetic, help("%*%"), see that:

multiplies 2 matrices, if conformable. if 1 argument vector, promoted either row or column matrix make 2 arguments conformable. if both vectors of same length, return inner product (as matrix).

so r interpret vector in whichever way makes matrix product sensible.

some examples illustrate:

> b <- c(7,10) > b [1]  7 10 > dim(b) <- c(1,2) > b      [,1] [,2] [1,]    7   10 > dim(b) <- c(2,1) > b      [,1] [1,]    7 [2,]   10 > class(b) [1] "matrix" > dim(b) <- null > b [1]  7 10 > class(b) [1] "numeric" 

a matrix vector dimension attribute. adding explicit dimension makes matrix, , r in whichever way makes sense in context.

and example of behavior in context of matrix multiplication:

> m <- matrix(1:2,1,2) > m      [,1] [,2] [1,]    1    2 > m %*% b      [,1] [1,]   27 > m <- matrix(1:2,2,1) > m %*% b      [,1] [,2] [1,]    7   10 [2,]   14   20 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -