Closed provedup closed 6 years ago
Try adding ungroup() at the end
Try adding ungroup() at the end
Where at the end do I put ungroup()
Try adding ungroup() at the end
Where at the end do I put ungroup()
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 == 1),
perc_survived = 100 * survivors / N) %>% ungroup()
I also have an issue. when I submit my code I get an error.
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), perc_survived = survivors / N * 100 )
When I submit this code, I get this.... Sourcing your script...
Error in source(e$script_temp_path, encoding = "UTF-8") : C:\Users\Dell\AppData\Local\Temp\Rtmpwxfko6/step_4_titanic.R:43:0: unexpected end of input 41: labels = c("Under 15", "15 to 50", 42: "Over 50"))) %>%
can someone help me here
Hi, I am doing an R course that uses Swirl. I am in chapter 12 of the R Programming Environment - Data Manipulation. I am stuck on the final problem about the Titanic Survivors. I began with code from the previous question, which creates the first data frame.
To solve this problem, I created this code:
Which gives this output:
The above output is wrong because the last column (perc_survived) is a character instead of a .
To solve this, I tell R to change the type to numeric with the as.numeric function.
which creates this output:
The new problem is that the output is rounded to 5 digits after the decimal place instead of 6 digits. I have tried every combination I can find, but have not been able to tell r to keep 6 decimals when it converts from character to numeric.
I'm stuck and need some guidance from a generous person. Thank you, Andrew