After recode from continuous variables into categorical. The summary for the new categorical variable doens't show how it summarize for categorical in levels we often see.
Please help!
尝试这个
A4 <- within(A4, resize <- factor(Size > 1000, c("S", "L")))
cut
正是这样做的。
A4$resize <- cut(A4$Size, breaks = c(-Inf, 1000, Inf), labels = c("S", "L"))
We can use findInterval
A4$resize <- with(A4, c('S', 'L')[findInterval(Size, 1000)])
Or using case_when
library(dplyr)
A4 %>%
mutate(resize = case_when(Size > 1000 ~ "S", TRUE ~ "L"))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.