0

I need to create matrix 100x100 and multiply by 2 every record bigger then 5000 and I'm giving up :/

Code for matrix

m <- matrix(1:10000, nrow = 100, ncol = 100)

Can somebody help me ?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • 1
    Can you make the example a bit smaller – akrun Jan 15 '20 at 19:09
  • Don't understand "multiply by 2 every record bigger then 5000"... can you show what do you mean? – ThomasIsCoding Jan 15 '20 at 19:12
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jan 15 '20 at 19:12

2 Answers2

2

I think this code solve your problem:

m[m > 5000] = 2*m[m>5000]

Also:

m = ifelse(m > 5000, 2*m, m)
Filipe Lauar
  • 434
  • 3
  • 8
0

n <- apply(m, 2, function(x) ifelse(x > 5000, x*2, x))

Ane
  • 335
  • 1
  • 11