Skip to contents

Emulates the times() and .* operators from Matlab.

Usage

times(a, b)

Arguments

a

first factor of the multiplication

b

second factor of the multiplication

Value

matrix with dimensions equal to the larger of the two factors

Details

This function basically handles elements of different length better than the * operator in R, at least as far as behavior from a Matlab user is expecting.

Examples

times(9, 6)
#>      [,1]
#> [1,]   54
x <- matrix(1:4, 2)
y <- c(10, 3)
print(x)
#>      [,1] [,2]
#> [1,]    1    3
#> [2,]    2    4
print(y)
#> [1] 10  3
times(x, y)
#>      [,1] [,2]
#> [1,]   10   30
#> [2,]    6   12
x * y
#>      [,1] [,2]
#> [1,]   10   30
#> [2,]    6   12