Learn R Programming

samplingR (version 1.0.1)

srs.sample: Simple Random Sample

Description

With this function you receive a simple random sample consisting on a list of the instances index

Usage

srs.sample(N, n, replace = FALSE, data)

Value

List of size n with numbers from 1 to N indicating the index of the data set's instances to be taken.

Arguments

N

Number of instances of the data set.

n

Number of instances of the returning sample.

replace

Whether the sample to be taken can have repeated instances or not.

data

Optional matrix or data.frame containing the population data. If specified an object of same class as data will be returned with sample instances.

Examples

Run this code
srs.sample(10,3)


data<-matrix(data=c(1:24), nrow=8)
N<-dim(data)[1]
sample<-srs.sample(N, 3, data = data)
sample

Run the code above in your browser using DataLab