write.gerbil: Write imputed datasets from gerbil objects to a file or files

View source: R/generics.R

write.gerbilR Documentation

Write imputed datasets from gerbil objects to a file or files

Description

Using a gerbil object as an input, this function writes imputed datasets to an output file.

Usage

write.gerbil(gerb, file = NULL, imp = NULL, tall = FALSE, row.names = FALSE)

Arguments

gerb

A gerbil object containing the imputed data.

file

The name of the file to which the imputed datasets are to be written. Which type of file (.xlsx or .csv) is created depends upon the extension of the parameter file.

imp

The imputed datasets which are to be written. Can be a scalar or, if multiple imputed datasets are to be written, a vector. All elements of imp should be integers greater than 0 but no greater than m, which is the number of imputed datasets in gerb. imp defaults to 1:m.

tall

A logical expression indicating whether the datasets are to be written in a tall (stacked) format or written separately. When writing to an XLSX file with tall = FALSE, one tab is created for each imputed dataset. When writing to a CSV file with tall = FALSE, one file is created for each imputed dataset (in this case, several file names will be created from the base string given by file).

row.names

A logical value indicating whether the row names of the datasets are to be written.

Details

The function writes imputed datasets to either an Excel (.xlsx) or a CSV (.csv) file, depending upon the extension of the parameter file. No other file types are supported. To write multiple imputed datasets simultaneously, specify imp as a vector with length greater than 1. Multiple imputed datasets are either written in a stacked format (if tall = TRUE) or written separately (if tall = FALSE).

Value

No returned value, but instead a data file is written to a specified directory.

Examples


#Load the India Human Development Survey-II dataset
data(ihd_mcar)

# Create a gerbil object
imps.gerbil <- gerbil(ihd_mcar, m = 5, ords = "education_level", semi = "farm_labour_days", 
       bincat = "job_field", n.cores = 1)

# Write all imputed datasets to separate CSV files
write.gerbil(imps.gerbil, file.path(tempdir(), "gerbil_example.csv"), imp = 1:5, tall = FALSE)

# Write all imputed datasets to a single CSV files
write.gerbil(imps.gerbil, file.path(tempdir(), "gerbil_example.csv"), imp = 1:5, tall = TRUE)

# Write all imputed datasets to an XLSX file
write.gerbil(imps.gerbil, file.path(tempdir(), "gerbil_example.xlsx"), imp = 1:5, tall = FALSE)



gerbil documentation built on Jan. 12, 2023, 5:10 p.m.