I am trying to recode the values of mixed alpha-number character variable with a data set I am running through pipes in R. I have loaded the following packages:
- tidyverse
- tidyr
- dplyr
- lubridate
- forcats
My original dataset consisted of 4 obs. of 325 variables. I changed the format and now have 1296 obs. of 3 variables:
- ID
- month_year
- value
Some sample data:
ID | month_year | value
----| ----| ----|
LA01 | Jan.1990 | 3.5
----| ----| ----|
LA02 | Jan.1990 | 195294.0
---- | ---- | ---- |
LA03 | Jan.1990 | 434343.0
---- | ---- | ---- |
LA01 | Feb.1990 | 3.0
---- | ---- | ---- |
LA02 | Feb.1990 | 195234.0
---- | ---- | ---- |
LA03 | Feb.1990 | 43325.0
---- | ---- | ---- |
Some sample output from a glimpse call for my data: My data:
> Observations: 1,296
Variables: 3
$ Series.ID <fctr>
> LAUMT064186000000003, LAUMT064186000000004, LAUMT064186000000005,
> LAUM...
$ month_year <chr> "Jan.1990", "Jan.1990", "Jan.1990",
> "Jan.1990", "Feb.1990", "Feb.1990",...
$ value <dbl> 3.5,
> 70296.0, 1952945.0, 2023241.0, 3.3, 66517.0, 1948964.0, 2015481.0,...
Problem to Solve I want to change the name of the values for "ID" (aka Series.ID). There are 4 values I have tried to change in my data frame, "tidier_labor", using:
tidier_labor %>%
mutate(Series.ID = fct_recode(Series.ID, unemployment_rate = "LAUMT064186000000003", unemployment = "LAUMT064186000000004", employment = "LAUMT064186000000005", labor_force = "LAUMT064186000000006"))
However I receive an error message reading
‘Series.ID’ converted to character stringError in as.environment(pos) : no item called "Series.ID" on the search list
It's possible that I need to make some kind of transformation so that my variables can be identified, but I am at a loss of how to do this. I have tried using 'as.character' or 'as.factor' but while the output may show the the data was transformed, when I use 'View' to look over my dataset, nothing has changed.
Any help would be welcome.
Thank you.