srsdf {NCStats}R Documentation

Extract a simple random sample from a data.frame.

Description

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

Usage

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

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")) )


[Package NCStats version 0.4.7 Index]