swirl

r: rounding when head data

馋奶兔 提交于 2020-01-05 07:27:20
问题 I am not able to figure out how to get r to correctly show the head of my data. This is an assignment for Swirl, so I have to figure out how to write my code in a way that Swirl will accept as the answer. Swirl wants the final printout to look exactly like this: ## Pclass agecat Sex N survivors perc_survived ## <int> <fctr> <chr> <int> <int> <dbl> ## 1 Under 15 female 2 1 50.000000 ## 1 Under 15 male 3 3 100.000000 ## 1 15 to 50 female 70 68 97.142857 ## 1 15 to 50 male 72 32 44.444444 ## 1

Increasing Decimal Positions - Swirl - r Programming Environment 12 - Data Manipulation

蹲街弑〆低调 提交于 2019-12-11 17:31:49
问题 I am working on a question from swirl, r Programming Environment 12 Data Manipulation. I cannot figure out how to get r to give me the right number of digits after the decimal place. My code: titanic_4 <- titanic %>% select(Survived, Pclass, Age, Sex) %>% filter(!is.na(Age)) %>% mutate(agecat = cut(Age, breaks = c(0, 14.99, 50, 150), include.lowest = TRUE, labels = c("Under 15", "15 to 50", "Over 50"))) %>% group_by(Pclass,agecat,Sex) %>% summarize(N=n(), survivors = sum(Survived))%>% mutate