Message Boards Message Boards

GROUPS:

Convert a range of random numbers in a list into a list of variable

Posted 1 month ago
189 Views
|
3 Replies
|
2 Total Likes
|

I would like to convert a range of random numbers in a list into a list of variables where each variable takes on one of those ranges.

n = 10;
t = Table[Random[], n]

{0.501302, 0.0565893, 0.733928, 0.751724, 0.27226, 0.133514, \
0.111942, 0.104862, 0.664754, 0.490448}

replace those value < .4 with b, replace those values > .4 but < .7 with c.

3 Replies
Posted 1 month ago

`

Table[Which[# < .4, b, # < .7, c, True, #] &[t[[i]]], {i, 1, 
  Length[t]}]`
Posted 1 month ago
Table[Which[# < .4, b, # < .7, c, True, #] &[t[[i]]], {i, 1, Length[t]}]

beautifully done, thank you Jaeyong Sung

Posted 1 month ago
Which[# < .4, b, # < .7, c, True, #] & /@ t
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract