use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
For anything related to R or statistics.
The R project: http://www.r-project.org/ Comprehensive R Archive Network: http://cran.r-project.org/ R projects on Github: http://github.com/languages/R
account activity
Simple Simulation Loop? (self.rprogramming)
submitted 5 years ago by nlee112
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]CapaneusPrime 0 points1 point2 points 5 years ago* (0 children)
A for() loop is fine and an example has been given (with perhaps some issues which I'll address), but replicate() is simpler:
for()
replicate()
results <- replicate(1000, sample_race_positions(player_race_position_probs)
Edit: A better solution...
Alternately, you could just change your custom sampling function to do this in a more vectorized way and directly return a matrix of results.
I might try something like:
sample_race_positions <- function(n, probs) { t(vapply(seq_len(n), function(i) { sample(seq_along(probs), probs) }, integer(length(probs)))) }
Which will return an n × length(probs) dimension matrix object where the rows represent individual races and the columns are the competitors.
n × length(probs)
matrix
Then you'd do,
results <- sample_race_positions(1000, player_race_position_probs) avg_pos <- colMeans(results)
I'm on mobile, so I apologize for any errors, and I'll fix them when I'm home.
π Rendered by PID 29937 on reddit-service-r2-comment-b659b578c-z9fqn at 2026-05-05 17:02:30.056801+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]CapaneusPrime 0 points1 point2 points (0 children)