DS4PS / ays-r-coding-sum-2022

Introductory data science course in R, taught at the Andrew Young School GSU.
http://ds4ps.org/ays-r-coding-sum-2022/
2 stars 2 forks source link

lab 6 part 2 issue #14

Closed kyarosiuk1 closed 2 years ago

kyarosiuk1 commented 2 years ago

How do we change format on ONET-SOCCode in Salaries? I tried to add two digits, but it did not work.. Salaries <- format(Salaries$ONET-SOCCode, digits=2)

and the code that is given in the assignment does not changed it to .00

mutate(O*NET-SOC Code = gsub(x = O*NET-SOC Code, pattern = "$", replacement = "\.00"), Median = gsub(x = Median, pattern = ",", replacement = ""), Median = as.numeric(Median))

jamisoncrawford commented 2 years ago

At what point in the code does it return an error?

url <- paste0("https://raw.githubusercontent.com/DS4PS/ays-r-cod",
              "ing-sum-2022/main/labs/bls_occupation_salaries.csv")

Salaries <- read_csv(url, 
                     col_select = c("O*NET-SOC Code" = "OCC_CODE", 
                                    "Title" = "OCC_TITLE", 
                                    "Median" = "A_MEDIAN")) %>% 
  mutate(`O*NET-SOC Code` = gsub(x = `O*NET-SOC Code`, 
                                 pattern = "$", 
                                 replacement = "\\.00"),
         Median = gsub(x = Median, 
                       pattern = ",", 
                       replacement = ""),
         Median = as.numeric(Median))
kyarosiuk1 commented 2 years ago

i do not really get an error...the code runs through but does not add .00 in Salaries data... The only error I get is when I run the last part (see below)

Median = as.numeric(Median))

this is the error I get when I run it chr (3): OCC_CODE, OCC_TITLE, A_MEDIAN

ℹ Use spec() to retrieve the full column specification for this data. ℹ Specify the column types or set show_col_types = FALSE to quiet this message. Error: (converted from warning) Problem while computing Median = as.numeric(Median). ℹ NAs introduced by coercion

jamisoncrawford commented 2 years ago

Why are you trying to convert it to class "numeric"?

These are labels, so you'll want to treat them as class "character"! Just like ZIP codes or phone numbers, it doesn't make sense to treat them numerically, yeah? Let me know if this helps!

kyarosiuk1 commented 2 years ago

I am sorry, but I am still not clear how to convert 00-0000 on Salaries data into 00-0000.00 the code i gave you was provided as a part of the homework and I am also confused why that code is converting to class "numeric" but this is what was given in the homework code... I was using below code to add the 2 digits at the end, but that does not work... thank you so much for your help!

Salaries <- format(Salaries$ONET-SOCCode, digits=2)

kyarosiuk1 commented 2 years ago

please disregard the above. I just figured out how to convert :) will keep moving forward. Thank you so much for your help!