Learn R Programming

RDS (version 0.9-10)

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
)

Value

An rds.data.frame object

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.

Examples

Run this code
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)

Run the code above in your browser using DataLab