# to write existing data `X`, `bim`, `fam` into files "data.bed", "data.bim", and "data.fam",
# run like this:
# write_plink("data", X, bim = bim, fam = fam)
# The following example is more detailed but also more awkward
# because (only for these examples) the package must create the file in a *temporary* location
# here is an example for a simulation
# create 10 random genotypes
X <- rbinom(10, 2, 0.5)
# replace 3 random genotypes with missing values
X[sample(10, 3)] <- NA
# turn into 5x2 matrix
X <- matrix(X, nrow = 5, ncol = 2)
# simulate a trait for two individuals
pheno <- rnorm(2)
# write this data to BED/BIM/FAM files
# output path without extension
file_out <- tempfile('delete-me-example')
# here all of the BIM and FAM columns except `pheno` are autogenerated
write_plink(file_out, X, pheno = pheno)
# delete all three outputs when done
delete_files_plink( file_out )
Run the code above in your browser using DataLab