Search code examples
rtidyversetidycensus

Tidy Census: Removing MOE columns


I am pulling some data through tidycensus from the ACS. When I do this, I get two columns for all the variables I included. Since my final dataset has a lot of variables, is it possible to turn off the pull of the MOE. Failing that, can I delete all columns ending with M, and remove the E at the end of the estimate columns?

dv_acs = c(
  var1 = "B25002_001", 
  var2 = "B25002_002", 
  var3 = "C24010_039"
)

acs_vars <- get_acs(
    geography = "tract",
    state = "MD",
    variables = dv_acs ,
    year = 2009,
    output = "wide",
    geometry = FALSE
)

Solution

  • I don't know how to use tidycensus ... but can answer the second part of your question. You can certainly delete and rename the columns with standard tidyverse functions.

    library(tidyverse)
    df <- tibble(
      column1M = rnorm(10),
      column1E = rnorm(10),
      column2M = rnorm(10),
      column2E = rnorm(10)
    )
    
    df %>% select(-ends_with("M")) %>%
      rename_with(~str_remove(.x, "E$"))