I am trying to use an ifelse statement to provide a "message" based on the value of a calculated mean.
Here is the code I have. I'm not getting an error message but the level of sleep is not in the correct place.
summary_sleep<-sleep_day %>%
group_by(Id)%>%
summarise(max_slept = max(TotalMinutesAsleep),
mean_sleep=mean(TotalMinutesAsleep),
sum_sleep=sum(TotalMinutesAsleep),
number_sleep_entries=length(TotalMinutesAsleep))
summary_sleep$level_of_sleep =
ifelse(summary_sleep$mean_sleep >= 460, "Too much sleep (OVER 460)",
ifelse(summary_sleep$mean_sleep >= 360 && summary_sleep$mean_sleep
<=459, "Good sleep (360-460)",
ifelse(summary_sleep$mean_sleep >= 200 && summary_sleep$mean_sleep
<=360, "Bad sleep (200-360)",
ifelse(summary_sleep$mean_sleep >0 && summary_sleep$mean_sleep <200,
"Bad sleep (0-200)"))))
ID | mean_sleep | level_of_sleep |
---|---|---|
1 | 294.0000 | Good sleep (360-460) |
2 | 61.000 | Good sleep (360-460) |
3 | 506.1786 | Too much sleep (OVER 460) |
Aucun commentaire:
Enregistrer un commentaire