DS4PS / ddmp-uw-class-spring-2019

Data-Driven Management & Policy Course at UW, Spring 2019
https://ds4ps.github.io/ddmp-uw-class-spring-2019/
4 stars 3 forks source link

Lab 4 #6

Open wainman19 opened 5 years ago

wainman19 commented 5 years ago

Although I have the correct answers for part 2 " Get the max value of human development index for each type of democracy." My method is not correct. How do I get all 4 answers together?

mydata[,c('demType','hdi')]

mydata2 <- mydata %>% select(-demScore, -country)

mydata2 %>% top_n(1, hdi)

mydata2 %>% top_n(1, demType)

max(c(mydata2$hdi, mydata2$demType))

library(dplyr) filter( mydata2, hdi >= .86 & mydata2$demType=='Authoritarian')

library(dplyr) filter( mydata2, hdi >= .93 & mydata2$demType=='Flawed democracy')

library(dplyr) filter( mydata2, hdi >= .80 & mydata2$demType=='Hybrid regime')

wainman19 commented 5 years ago

@MAGALLANESJoseManuel

profemagallanes-unmsm commented 5 years ago

Lab solutions will be posted later. I encourage you to take some time to apply what was taught in the lesson.

profemagallanes-unmsm commented 5 years ago

Try the two ways I taught.

wainman19 commented 5 years ago

Got it!

tapply(X=mydata2$hdi,INDEX=list(mydata2$demType),FUN = max)

Authoritarian Flawed democracy Full democracy Hybrid regime

0.863 0.933 0.953 0.814

mydata2 %>%
group_by( demType, ) %>%
summarize(max(hdi))

A tibble: 4 x 2

demType max(hdi)

1 Authoritarian 0.863

2 Flawed democracy 0.933

3 Full democracy 0.953

4 Hybrid regime 0.814

wainman19 commented 5 years ago

Awww, it was the "group by" portion I was missing! Thanks.

On Fri, Apr 26, 2019 at 11:12 AM taylynners04 notifications@github.com wrote:

Hi @wainman19 https://github.com/wainman19

I found this code online that worked for me:

library(dplyr) hdidata %>% group_by(demType) %>% top_n(1, hdi)

Where "hdidata" is my dataset, and "demType" and "hdi" are the variable names.

Hopefully this is helpful!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/DS4PS/ddmp-uw-class-spring-2019/issues/6#issuecomment-487150715, or mute the thread https://github.com/notifications/unsubscribe-auth/ALYDSUM7YG4CRJFTET6D633PSNATPANCNFSM4HILM6UQ .