So I dummied some data up (for future reference, it is very helpful if you do this yourself — we often call this a "reprex"— see link below my code). I didn't follow the exact parameters for your assignment, which is good, since you'll get a chance to play around with it!
I think that working with the forcats package will make your life much easier:
Below I've used fct_inorder(), for example, to make sure that the factor levels were sequential.
To reverse the order of levels, you can use fct_rev(), which I don't do below.
suppressPackageStartupMessages(library(tidyverse))
mydata <- tibble::tribble(
~subject, ~confident,
"Alice", "strongly agree",
"Bob", "neither agree nor disagree",
"Cynthia", "moderately disagree",
"Dylan", "moderately agree",
"Eric", "strongly disagree",
"Frank", "moderately agree",
"Gina", "strongly agree"
)
glimpse(mydata)
#> Observations: 7
#> Variables: 2
#> $ subject <chr> "Alice", "Bob", "Cynthia", "Dylan", "Eric", "Frank", "…
#> $ confident <chr> "strongly agree", "neither agree nor disagree", "moder…
# currently both are characters, we want `confident` to be a factor
library(forcats)
mylevels <- factor(c("strongly disagree", "moderately disagree",
"neither agree nor disagree", "moderately agree",
"strongly agree"))
mylevels <- fct_inorder(mylevels, ordered = TRUE)
mydata <- mydata %>%
mutate("confident" = factor(confident, levels = mylevels))
glimpse(mydata)
#> Observations: 7
#> Variables: 2
#> $ subject <chr> "Alice", "Bob", "Cynthia", "Dylan", "Eric", "Frank", "…
#> $ confident <fct> strongly agree, neither agree nor disagree, moderately…
mydata <- mydata %>%
mutate(confident_num = as.integer(confident))
mydata
#> # A tibble: 7 x 3
#> subject confident confident_num
#> <chr> <fct> <int>
#> 1 Alice strongly agree 5
#> 2 Bob neither agree nor disagree 3
#> 3 Cynthia moderately disagree 2
#> 4 Dylan moderately agree 4
#> 5 Eric strongly disagree 1
#> 6 Frank moderately agree 4
#> 7 Gina strongly agree 5
Created on 2019-03-01 by the reprex package (v0.2.1)
There's a nice "getting started" guide to forcats here:
https://forcats.tidyverse.org/articles/forcats.html