0

I have 3 vector: a (101 by 45), b (101 by 45) and k (1 by 45) to be manipulated to A+B*K^T where A is rep(a,45), B is rep(b,45) and K is t(matrix(rep(k,45),ncol=45)) I have a matlab background and see everything as matrices, this view don't seem to be best for R. I struggle to adapt and have created following script that I'm sure can be much improved

nof=45
A = matrix(rep(a,nof),ncol=nof)
B = matrix(rep(b,nof),ncol=nof)
K = t(matrix(rep(k,nof),ncol=nof))
mf <- A+B%*%K
plot(mf)

Can this be written in more R fashion?

Orongo
  • 285
  • 1
  • 6
  • 16
  • Please make sure your code is [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Thomas K Apr 02 '17 at 19:16
  • Please include `a`, `b`, and `k` so your code is runnable. I find the code to be readable; a shortcut could be `A <- replicate(nof, a)` instead of `A <- matrix(rep(a, nof), ncol=nof)`. – josliber Apr 02 '17 at 20:33
  • Please note that Stack Exchange has a site codereview.stackexchange.com where you can post running code and get feedback on coding style. This sort of question would be a better fit there. If you update your code to run by including `a`, `b`, and `k` I could migrate it. – josliber Apr 02 '17 at 20:35

0 Answers0