Note: This is for a class. I'd prefer guidance over an answer if possible.
So I'm new to R. I'm trying to plot the population of Oklahoma from 2010-2019 (and predict 5 years into the future) using a linear regression.
The CSV file that I have has a lot of columns, specifically, the population for each year is in a separate column like
Name, POPULATION2010, POPULATION2011,POPULATION2012, etc.
What I want is for the columns to be:
Name, Year, Population,
I used the following code in hopes of doing that
pops <- read_csv("Desktop/populations/nst-est2019-popchg2010_2019.csv")
OK_pops<- filter(pops, NAME == "Oklahoma")
pop_OK <- pivot_longer(OK_pops,
cols=starts_with("ESTIMATEPOPULATION"),
names_to="Year",
names_prefix = "yr",
values_to = "Population",
)
What is does is removed all of the POPUATION columns, but it doesn't create the Year and population column that I'm needing
Thank you for you assistance.