Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

as.rds.data.frame

Coerces a data.frame object into an rds.data.frame object.


Description

This function converts a regular R data frame into an rds.data.frame. The greatest advantage of this is that it performs integrity checks and will fail if the recruitment information in the original data frame is incomplete.

Usage

as.rds.data.frame(
  df,
  id = if (is.null(attr(df, "id"))) "id" else attr(df, "id"),
  recruiter.id = if (is.null(attr(df, "recruiter.id"))) {     "recruiter.id" } else
    attr(df, "recruiter.id"),
  network.size = if (is.null(attr(df, "network.size.variable"))) {    
    "network.size.variable" } else attr(df, "network.size.variable"),
  population.size = if (all(is.na(get.population.size(df, FALSE)))) {     NULL } else
    get.population.size(df, FALSE),
  max.coupons = if (is.null(attr(df, "max.coupons"))) {     NULL } else attr(df,
    "max.coupons"),
  notes = if (is.null(attr(df, "notes"))) {     NULL } else attr(df, "time"),
  time = if (is.null(attr(df, "time"))) {     NULL } else attr(df, "time"),
  check.valid = TRUE
)

Arguments

df

A data.frame representing an RDS sample.

id

The unique identifier.

recruiter.id

The unique identifier of the recruiter of this row.

network.size

The number of alters (i.e. possible recruitees).

population.size

The size of the population from which this RDS sample has been drawn. Either a single number, or a vector of length three indicating low, mid and high estimates.

max.coupons

The number of recruitment coupons distributed to each enrolled subject (i.e. the maximum number of recruitees for any subject).

notes

Data set notes.

time

the name of the recruitment time variable. optional.

check.valid

If true, validity checks are performed to ensure that the data is well formed.

Value

An rds.data.frame object

Examples

dat <- data.frame(id=c(1,2,3,4,5), recruiter.id=c(2,-1,2,-1,4),
                  network.size.variable=c(4,8,8,2,3))
as.rds.data.frame(dat)

RDS

Respondent-Driven Sampling

v0.9-3
LGPL-2.1
Authors
Mark S. Handcock [aut, cre], Krista J. Gile [aut], Ian E. Fellows [aut], W. Whipple Neely [aut]
Initial release
2021-03-11

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.