Skip to main content
Statistics LibreTexts

13: Sampling in R

  • Page ID
    7652
  • First we load the necessary libraries and set up the NHANES adult dataset

    library(tidyverse)
    library(ggplot2)
    library(knitr)
    library(cowplot)
    
    set.seed(123456)
    opts_chunk$set(tidy.opts=list(width.cutoff=80))
    options(tibble.width = 60)
    
    
    # load the NHANES data library
    library(NHANES)
    
    # create a NHANES dataset without duplicated IDs 
    NHANES <-
      NHANES %>%
      distinct(ID, .keep_all = TRUE) 
    
    #create a dataset of only adults
    NHANES_adult <- 
      NHANES %>%
      filter( 
        Age >= 18
      ) %>%
      drop_na(Height)