I am trying to extract data from a certain row from a csv file. When I run this code I get all three columns of Exam 1, 2 & 3 when I only want Exam 2 and the difference in the final exam. It also does not display the gender under the heading, only N/A. Does anyone have any idea what I'm missing? I can't seem to get it right.
But in general, it sounds like you want to select a subset of columns from your whole dataset. The dplyr function for doing that is (intuitively) called, select(). If you want just the Exam2 and diffs columns, you would do this:
As for the other issue regarding the gender variable, it will be easier to help if you include a sample of your data as well as what you expect the output to be.
I have only read in the data so this is my starting point. So in my csv file I have 4 columns of data with the folloqing headings: Gender, Exam 1, Exam 2, Exam 3 and Final.
And I want to extract the gender column along with exam 2 and the difference in exam 2 and the final score in these tests. I tried the code above and added in Gender in the select function but it still does not display the gender only N/A. It is displaying the Exam 2 and difference though
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.