Displaying 1 result from an estimated 1 matches for "colnn".
Did you mean:
colin
2024 Feb 29
2
[External] converting MATLAB -> R | element-wise operation
I decided to do a direct comparison of transpose and sweep.
library(microbenchmark)
NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE) # Example matrix
lambda <- c(2, 3, 4) # Example vector
colNN <- t(NN)
microbenchmark(
sweep = sweep(NN, 2, lambda, "/"),
transpose = t(t(NN)/lambda),
colNN = colNN/lambda
)
Unit: nanoseconds
expr min lq mean median uq max neval cld
sweep 13817 14145 15115.06 14350 14657.5 75932 100 a
transpose 1...