Watts-College / cpp-527-spr-2022

https://watts-college.github.io/cpp-527-spr-2022/
0 stars 1 forks source link

Final Project - Part1 I, Step 8 #39

Open mmonakho opened 2 years ago

mmonakho commented 2 years ago

Getting this error in Step 8, can't move any further. Please help...

t.salary <-

  • d %>%
  • 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) ) Error: Problem with filter() input ..1. i Input ..1 is !is.na(title) & title != "". x comparison (2) is possible only for atomic and list types Run rlang::last_error() to see where the error occurred. In addition: Warning message: In is.na(title) : is.na() applied to non-(list or vector) of type 'closure'

pander( t.salary ) Error in pander(t.salary) : object 't.salary' not found

Dselby86 commented 2 years ago

t.salary is being defined inside of a function.

You can't reference it outside of the function.

On Thu, Mar 3, 2022 at 12:14 PM mmonakho @.***> wrote:

Getting this error in Step 8, can't move any further. Please help...

t.salary <-

  • d %>%

  • 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) ) Error: Problem with filter() input ..1. i Input ..1 is !is.na(title) & title != "". x comparison (2) is possible only for atomic and list types Run rlang::last_error() to see where the error occurred. In addition: Warning message: In is.na(title) : is.na() applied to non-(list or vector) of type 'closure'

pander( t.salary ) Error in pander(t.salary) : object 't.salary' not found

— Reply to this email directly, view it on GitHub https://github.com/Watts-College/cpp-527-spr-2022/issues/39, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4EHBYPJCNAYO4UJZJYBDLU6EFQNANCNFSM5P3L254Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

mmonakho commented 2 years ago

How do I change it so I can reference it outside of the function?

Dselby86 commented 2 years ago

end the function with a return statement.

Example: return(t.salary).

Then when you call the function make it an assignment statement

Example: salary.table = sample_function()

then you can use salary.table as the results of your function

Look over your previous code in the monte hall labs for an example.

On Thu, Mar 3, 2022 at 12:30 PM mmonakho @.***> wrote:

How do I change it so I can reference it outside of the function?

— Reply to this email directly, view it on GitHub https://github.com/Watts-College/cpp-527-spr-2022/issues/39#issuecomment-1058410411, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4EHBZBOWVHJSW7Q4KFEFTU6EHNLANCNFSM5P3L254Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

mmonakho commented 2 years ago

I returned t.salary and got another error:

mmonakho commented 2 years ago

Error: unexpected symbol in: " mutate( p= round( n/sum(n), 2) ) return(t.salary)."

My code:

create_salary_table <- function() { t.salary <- d %>% 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). }