{"action":"closed","issue":{"url":"https://api.github.com/repos/ramhiser/itertools2/issues/37","labels_url":"https://api.github.com/repos/ramhiser/itertools2/issues/37/labels{/name}","comments_url":"https://api.github.com/repos/ramhiser/itertools2/issues/37/comments","events_url":"https://api.github.com/repos/ramhiser/itertools2/issues/37/events","html_url":"https://github.com/ramhiser/itertools2/issues/37","id":50875154,"number":37,"title":"Random selection from an iterator/iterable object","user":{"login":"ramhiser","id":261183,"avatar_url":"https://avatars.githubusercontent.com/u/261183?v=3","gravatar_id":"","url":"https://api.github.com/users/ramhiser","html_url":"https://github.com/ramhiser","followers_url":"https://api.github.com/users/ramhiser/followers","following_url":"https://api.github.com/users/ramhiser/following{/other_user}","gists_url":"https://api.github.com/users/ramhiser/gists{/gist_id}","starred_url":"https://api.github.com/users/ramhiser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramhiser/subscriptions","organizations_url":"https://api.github.com/users/ramhiser/orgs","repos_url":"https://api.github.com/users/ramhiser/repos","events_url":"https://api.github.com/users/ramhiser/events{/privacy}","received_events_url":"https://api.github.com/users/ramhiser/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ramhiser/itertools2/labels/wontfix","name":"wontfix","color":"ffffff"}],"state":"closed","locked":false,"assignee":{"login":"ramhiser","id":261183,"avatar_url":"https://avatars.githubusercontent.com/u/261183?v=3","gravatar_id":"","url":"https://api.github.com/users/ramhiser","html_url":"https://github.com/ramhiser","followers_url":"https://api.github.com/users/ramhiser/followers","following_url":"https://api.github.com/users/ramhiser/following{/other_user}","gists_url":"https://api.github.com/users/ramhiser/gists{/gist_id}","starred_url":"https://api.github.com/users/ramhiser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ramhiser/subscriptions","organizations_url":"https://api.github.com/users/ramhiser/orgs","repos_url":"https://api.github.com/users/ramhiser/repos","events_url":"https://api.github.com/users/ramhiser/events{/privacy}","received_events_url":"https://api.github.com/users/ramhiser/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2014-12-03T18:41:08Z","updated_at":"2015-07-31T21:26:24Z","closed_at":"2015-07-31T21:26:24Z","body":"In many cases, it makes a lot of sense to randomly select from some object (or iterator) by sampling the indices of the object. Example:\r\n\r\n```r\r\nset.seed(42)\r\nn <- nrow(iris)\r\nindices <- seq_len(n)\r\ntrain_idx <- sample(indices, 2/3 * n)\r\n\r\ntrain_data <- iris[train_idx, ]\r\ntest_data <- iris[-train_idx, ]\r\n```\r\n\r\nIf `n` is extremely large, the `indices` vector becomes extremely large. To avoid this overhead, it makes sense to have some interface like:\r\n\r\n```r\r\nit <- isample(iseq_len(n), 50)\r\nas.list(it) # vector of length 50\r\n```"}}