Hi!
I am looking to obtain the total population and total housing unit population for a PUMA using the 2018 ACS 1-year PUMS file for TX. I use these files often, but admittedly have never been tasked with deriving these numbers. I am using R in RStudio. So far, this is what I have:
# Set working directory
setwd(" ")
# Verify working directory
getwd()
# Load library
library(tidyverse)
library(tidycensus)
library(car)
library(dplyr)
library(matrixStats)
library(stringr)
library(survey)
library(srvyr)
# Load household data 2018 1-year ACS PUMS
pums2018h <-
read.csv("")
# Load person data 2018 1-year ACS PUMS
pums2018p <-
read.csv("")
# Merge household and person PUMS data
pums2018 <-
inner_join(pums2018h,
pums2018p,
by = c("SERIALNO","DIVISION", "PUMA", "REGION", "ST", "ADJINC"))
# Set variables of interest to include
pums2018_var <-
pums2018 %>% select (
SERIALNO,
AGEP,
PWGTP,
RELP,
SCH,
SCHG,
ST,
PUMA,
WAGP,
WKL,
ESR,
ADJINC,
BLD,
HHT,
HINCP,
NP,
WIF,
NR,
TEN,
TYPE,
WGTP
)
# Filter observations to Grayson County
puma2900 <- pums2018_var %>% filter(PUMA == 2900)
# Total population
(tot_pop <- count(puma2900, wt = PWGTP))
# Housing unit population (RELP=0-15)
(hsg_pop <- puma2900 %>% filter(RELP < 16) %>% count(wt = PWGTP))
I hope I copied over my code correctly—if not, please let me know.
The last two lines of code give me the following error: Error in count(., puma2900, wt = PWGTP) :
Argument 'x' is not a vector: list
What is going on and what is the correct way to tell R to calculate these items?
Thank you in advance.