Open wainman19 opened 5 years ago
@MAGALLANESJoseManuel
Lab solutions will be posted later. I encourage you to take some time to apply what was taught in the lesson.
Try the two ways I taught.
Got it!
tapply(X=mydata2$hdi,INDEX=list(mydata2$demType),FUN = max)
mydata2 %>%
group_by( demType, ) %>%
summarize(max(hdi))
max(hdi)
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 .
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')