DS4PS / cpp-528-fall-2020

Course shell for CPP 528 Foundations of Data Science III - Project Management
http://ds4ps.org/cpp-528-fall-2020/
1 stars 1 forks source link

Week 4 - Mutate error #31

Open ecking opened 3 years ago

ecking commented 3 years ago

Hello, I'm going through the code in tutorial for week 4 and when I get to the "average growth in median home value for the city" part I get this error when I put in the code and I'm not sure what it means. I'm literally just copying and pasting the code.

# average growth in median home value for the city

d <- 
  d %>%
  group_by( cbsaname ) %>%
  mutate( metro.mhv.change = median( mhv.change, na.rm=T ),
             metro.mhv.growth = 100 * median( mhv.growth, na.rm=T ) ) %>%
  ungroup()

Problem with mutate() input metro.mhv.change i the condition has length > 1 and only the first element will be used i Input metro.mhv.change is median(mhv.change, na.rm = T) i The error occurred in group 1: cbsaname = Abilene, TX the condition has length > 1 and only the first element will be usedProblem with mutate() input metro.mhv.change i the condition has length > 1 and only the first element will be used'

cenuno commented 3 years ago

Hi @ecking thank you for catching this! This is an error on my part.

Whenever one is using dplyr::group_by(), it is because one wants to calculate group level statistics. That requires the dplyr::summarize() function rather than dplyr::mutate(). If you make this change, the error should resolve.

Let me update the class website soon. Again, I appreciate you catching this error.

cenuno commented 3 years ago

@ecking - the mistake has been corrected now. Appreciate your help!