Description Usage Arguments Value Examples
View source: R/create_datasets.R
Takes vector of NHANES file names, loads them, and merges them all by SEQN. The function automatically loads the demo file, so you do not have to include "demo" in the character vector. If you do include demo, or if you accidentally include the same filename twice, the function will only return a single copy of each file.
1 | load_merge(vec_of_files = "demo", yr, data_dir = "./data")
|
vec_of_files |
A character vector of NHANES files (e.g., c("mcq", "biopro")) that identifies the stem of the desired file(s). The demo file is ALWAYS included because it has the survey weights. This vector should NOT include the final letter (e.g., _c) that indicates the wave (see yr). |
yr |
The year for which the file should be extracted. |
data_dir |
The directory in which all of your NHANES subdirectories (one for each year) reside. Default is the project "data" subdirectory (i.e., "./data") but if your data are elsewhere, you must specify the directory. Keep in mind that this will be a directory that contains all of your NHANES subdirectories. It is NOT the subdirectory for a specific year. Do not use a slash (/) at the end. |
Returns a dataframe (which is also a data.table) with one column for each variable in each file requested. Note that in some cases, there are multiple records per person (SEQN) in an NHANES file. In this case, a list is returned with each item in the list being a dataframe with multiple records per person. The prescription drug file (RXQ_RX) is an example. All files with one record per person are merged as usual, and returned as the first dataframe in the list.
1 2 3 4 5 6 7 8 9 10 | nhanes_directory <- paste0(system.file(package = "nhanes.tools"), "/extdata") # location of data in package extdata directory
files_to_load <- c("mcq") # demo doesn't need to be included and will always be returned
full <- load_merge(files_to_load, 2009, nhanes_directory)
dim(full)
## Not run:
# Example: load many files listed in character vector
listing <- c("mcq", "dex", "hcq", "hiq", "vix", "uc") # demo is assumed
full <- load_merge(listing, 2003, "./data")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.