Got it! It's best if you can include a small sample of the data that is contained in the CSV. Since you're the only one that has that particular CSV file, I don't know what's contained in it and why you might be seeing errors. Here's a great thread about how to include sample data in a post: Best Practices: how to prepare your own data for use in a `reprex` if you can’t, or don’t know how to reproduce a problem with a built-in dataset?
So for your example, I used the tribble()
function from the tibble
pacakge to create some made up data and then we can all use that same sample data to work through the problem.
In the first line of your mutate()
it seems like you are trying to convert the Gender variable to a factor. Are you doing this because you will be plotting the data later? In any case, if you remove the levels argument, I believe you'll get what you are looking for.
library(tidyverse)
exam.data <- tribble(
~Gender, ~Exam1, ~Exam2, ~Exam3, ~Final,
"male", 91, 88, 74, 90,
"female", 98, 90, 91, 95,
"female", 88, 78, 90, 86
)
exam.data %>%
mutate(
Gender = factor(Gender),
diffs = Final - Exam2
) %>%
select(Gender, Exam2, diffs)
#> # A tibble: 3 x 3
#> Gender Exam2 diffs
#> <fct> <dbl> <dbl>
#> 1 male 88 2
#> 2 female 90 5
#> 3 female 78 8
Created on 2018-11-13 by the reprex package (v0.2.1)