Message Boards Message Boards

0
|
3524 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

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

Posted 5 years ago

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.

POSTED BY: Raymond Low
3 Replies
Posted 5 years ago
Which[# < .4, b, # < .7, c, True, #] & /@ t
POSTED BY: Rohit Namjoshi
Posted 5 years ago
Table[Which[# < .4, b, # < .7, c, True, #] &[t[[i]]], {i, 1, Length[t]}]

beautifully done, thank you Jaeyong Sung

POSTED BY: Raymond Low
Posted 5 years ago

`

Table[Which[# < .4, b, # < .7, c, True, #] &[t[[i]]], {i, 1, 
  Length[t]}]`
POSTED BY: Jaeyong Sung
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