DS4PS / cpp-529-spr-2020

Course shell for CPP 529 Data Practicum on Community Analytics for Spring 2020.
http://ds4ps.org/cpp-529-spr-2020
1 stars 1 forks source link

Questions About Lab #6 #11

Open Niagara1000 opened 4 years ago

Niagara1000 commented 4 years ago

Hi,

I am confused about what this part of the code means:

Under part 1 Regression Model -> Grab Census Data, we have this code:

census <-map_dfr(
  years,
  ~ get_acs(
geography = "county",
variables = c(
              HousePrice = 'B25077_001', #Median Value of  Housing Units
              total_pop ='B01001_001',
              pop_white = 'B01001H_001',  # not hispanic
              pop_black = 'B01001B_001',
              pop_hispanic = 'B01001I_001',
              below_poverty = 'B05010_002',
              speak_english = 'B06007_002',
              speak_spanish = 'B06007_003',
              bachelors = 'B06008_002',
              married = 'B06008_003',
              no_hs = 'B06009_002',
              hs = 'B06009_003',
              bach_degree = 'B06009_005',
              grad_degree = 'B06009_006'),
year = .x  
),
  .id = "year"
)

what does the .x and .id refer to?

AntJam-Howell commented 4 years ago

@Niagara1000 'years' is the list we created that contains two elements, 2007 and 2012. years in our case is the .x that is required as an input field for the map_dfr function (link). year is part of the get_acs function and instead of directly saying year 2007, we enter in .x, which calls the 'years' list containing our two values, 2007 and 2012. get_acs makes the call on the 2007 data, then makes the call again on the 2012 data, and then combines that output into a data frame. .id=year is the variable name assigned to the 2007 and 2012 years. You can change .id="year" to .id="Test" and look at the data output and you will see the variable name is changed.