list.sample: Sample a list or vector

Description Usage Arguments Examples

View source: R/list.sample.R

Description

Sample a list or vector

Usage

1
list.sample(.data, size, replace = FALSE, weight = 1, prob = NULL)

Arguments

.data

A list or vector

size

integer. The size of the sample

replace

logical. Should sampling be with replacement?

weight

A lambda expression to determine the weight of each list member, which only takes effect if prob is NULL.

prob

A vector of probability weights for obtaining the elements of the list being sampled.

Examples

1
2
x <- list(a = 1, b = c(1,2,3), c = c(2,3,4))
list.sample(x, 2, weight = sum(.))

Example output

$c
[1] 2 3 4

$b
[1] 1 2 3

rlist documentation built on Sept. 5, 2021, 5:30 p.m.