Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step 5: Convert Salary to Numeric #87

Open
WSKQ23 opened this issue Oct 9, 2021 · 1 comment
Open

Step 5: Convert Salary to Numeric #87

WSKQ23 opened this issue Oct 9, 2021 · 1 comment

Comments

@WSKQ23
Copy link

WSKQ23 commented Oct 9, 2021

Hello @lecy
I am having challenge with the cleaning of my salary data that I used to produce my salary summaries. I used the codes below to clean;

remove_dollar<- gsub( "\\$", " ", d$Salary )
  dollar_removed <- gsub(",", "", remove_dollar)
  salary <- head(dollar_removed %>% as.numeric())
 salary

but while producing my report I realized that all the values for q25, q50 and q75 are the same. I think I have issue with cleaning the salary that I used for

create_salary_table <- function (dat3)
{
  t.salary <- 
    dat3 %>% 
    filter( ! is.na( title ) & title != "") %>% 
    group_by( title, gender ) %>% 
    summarize( q25=quantile(salary,0.25),
               q50=quantile(salary,0.50),
               q75=quantile(salary,0.75),
               n=n() ) %>% 
    ungroup() %>% 
    mutate( p= round( n/sum(n), 2) )

  return(t.salary)
}

Please any help sir

@lecy
Copy link
Collaborator

lecy commented Oct 9, 2021

Are you ever assigning salary back to d?

remove_dollar<- gsub( "\\$", " ", d$Salary )
  dollar_removed <- gsub(",", "", remove_dollar)
  salary <- head(dollar_removed %>% as.numeric())
 salary

Try something like:

unstring_salary <- function(x)
{
  x <- gsub( "\\$", " ", x )
  x <- gsub(",", "", x )
  x <- as.numeric( x )
  return( x )
}

d$salary <- unstring_salary( d$Salary )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants