-1

enter image description here

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!

Will N
  • 1
  • 1
  • 1
    Converting your variable `resize`to a factor will show you the levels when calling `summary()`. – stefan Oct 03 '20 at 11:04
  • Please don't add data/code as image. Read about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). – Ronak Shah Oct 03 '20 at 12:16

3 Answers3

1

Try this

A4 <- within(A4, resize <- factor(Size > 1000, c("S", "L")))
ekoam
  • 8,744
  • 1
  • 9
  • 22
0

cut does precisely this.

A4$resize <- cut(A4$Size, breaks = c(-Inf, 1000, Inf), labels = c("S", "L"))
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
0

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"))
akrun
  • 874,273
  • 37
  • 540
  • 662