eyk801 / mp3

For MiniProject 3 in SDS192
0 stars 0 forks source link

Cannot mutate new column to categorize trail difficulties based on length #7

Closed jlin47 closed 6 years ago

jlin47 commented 6 years ago

trails_1<- trails %>% group_by(name) %>% summarize(num_segments = n(), total_length = sum(computed_length)) %>% arrange(desc(total_length))%>% mutate (Difficulty= if_else(total_length<1000, "Easy", ifelse(total_length<2000, "Moderate", "Hard")))

Error in mutate_impl(.data, dots) : Evaluation error: both operands of the expression should be "units" objects.

jlin47 commented 6 years ago

Solution: use as.numeric()

trails_1<- trails %>% group_by(name) %>% summarize(num_segments = n(), total_length = sum(computed_length)) %>% arrange(desc(total_length))%>% mutate (Difficulty= if_else(as.numeric(total_length)<1000, "Easy", ifelse(as.numeric(total_length)<2000, "Moderate", "Hard")))