Scilab Home page | Wiki | Bug tracker | Forge | Mailing list archives | ATOMS | File exchange
Scilab-Branch-6.1-GIT
Change language to: Français - Português - 日本語 - Русский

# sample

Sampling with replacement

### Syntax

`s = sample(n,X,orient)`

### Arguments

n

positive integer (size of sample)

X

matrix. Samples will be extracted from this matrix.

orient

Optional parameter. Admissible values are `{'*'}, 1, 2, 'r'` or `'c'`. The orientation to sample rows or columns. See Description below.

s

vector or matrix containing sample

### Description

This function returns a vector or matrix. It contains a random sample of `n` extractions, with replacement, from the matrix `X`.

`s = sample(n, X)` (or `s = sample(n, X, '*')`) returns a vector `s` whose values are a random sample of `n` values, extracted with replacement, from `X`.

`s = sample(n, X, 'r')` (or, equivalently, `s = sample(n, X, 1)`) returns a matrix of size `size(X,'r') * n`. It contains a random sample of `n` rows, extracted with replacement, from the rows of `X`.

`s = sample(n, X, 'c')` (or, equivalently, `s = sample(n, X, 2)`) returns a matrix of size `n * size(X, 'c')`. It contains a random sample of `n` columns, extracted with replacement from the columns of `X`.

### Random number generator

`sample` is based on grand for generating the random samples. Use `grand("setsd", seed)` to change the seed for `samplef`.

```seed = getdate("s");
grand("setsd", seed); //sets the seed to current date

seed = 0;
grand("setsd", seed); //sets the seed to default value```

### Examples

```X = ['a' 'dd' 'arreu'; 'ber' 'car' 'zon']
s = sample(25, X)
s = sample(25, X, 'r')
s = sample(25, X, 'c')```

• samplef — sample values with replacement from a population with given frequencies.
• samwr — Sampling without replacement
• grand — Random numbers

 Report an issue << rand random samplef >>

 Scilab EnterprisesCopyright (c) 2011-2017 (Scilab Enterprises)Copyright (c) 1989-2012 (INRIA)Copyright (c) 1989-2007 (ENPC)with contributors Last updated:Mon Jan 03 14:23:23 CET 2022