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.
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
)
An rds.data.frame object
A data.frame representing an RDS sample.
The unique identifier.
The unique identifier of the recruiter of this row.
The number of alters (i.e. possible recruitees).
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.
The number of recruitment coupons distributed to each enrolled subject (i.e. the maximum number of recruitees for any subject).
Data set notes.
the name of the recruitment time variable. optional.
If true, validity checks are performed to ensure that the data is well formed.
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