-1

I am working with a table that contains various values taken from high school seniors by an online questionnaire. One of the questions is what one's favorite beverage is. I would like to compare a favorite drink along with how many hours of sleep the individual gets in a night.

The beverage column has coffee, energy drinks, juice, milk, soft drinks (caffeine), soft drinks(non-caffeine, sports drink, tea, water, and other.

I would like to mutate all of the drink columns down to 1 Not_water and 2 Water so I could perform a t-test on the data.

Table Name: HS18, Column Names: Beverage, Weekend_Sleep

LA Riddle
  • 1
  • 1
  • 1
    `transform(HS18, Beverage_dichotomous = ifelse(Beverage == "water", "2 Water", "1 Not_water"))`? – Maurits Evers Oct 08 '20 at 04:51
  • Please add data using `dput` and show the expected output for the same. 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 08 '20 at 05:19

1 Answers1

0
library(tidyverse)

HS18  %>%
  mutate(drink = fct_other(Beverage, 
                          keep = "water", 
                          other_level = "not_water")
  )
meriops
  • 997
  • 7
  • 6