srsdf: Extract a simple random sample from a data.frame.

Description Usage Arguments Value See Also Examples

View source: R/misc-utils.R

Description

Extract a simple random sample from a data.frame, allowing user to choose particular variables.

Usage

1
srsdf(df, n, replace = FALSE, vars = NULL, removeRowNames = TRUE)

Arguments

df

The data frame to be sampled from.

n

Number of individuals (i.e., rows) to sample.

replace

A logical that indicates whether sampling with replacement should be used or not (default).

vars

A vector of strings that indicates which variables to include in the returned data.frame.

removeRowNames

A logical that indicates whether the rownames should be removed from the resultant data.frame.

Value

Returns a data.frame of rows sampled from df. Optionally, only includes the columns listed in vars.

See Also

sample.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data(ABDLakes)

# sample all variables without replacement
( res1 <- srsdf(ABDLakes,50) )

# sample two variables without replacement
( res2 <- srsdf(ABDLakes,50,vars=c("name","area")) )

# sample two variables with replacement
( res3 <- srsdf(ABDLakes,50,replace=TRUE,vars=c("name","area")) )

droglenc/NCStats documentation built on June 5, 2021, 2:06 p.m.