This post is my first on R and it will describe a method to reverse scores using R.
In many instruments (i.e., questionnaires) some items are phrased so that a strong agreement indicates something negative (e.g., “When there is music in the room I find it hard to concentrate on reading”). For more information on reverse scoring, please see my earlier post: Reverse scoring in Python. Since I was more familiar with Python compared to R, and I had no a clue on how to do this in SPSS, I wrote a Python script. The Python script used a function that used Pandas DataFrame and it reversed the scores nice and quickly.
However, in R was pretty much as simple to do reverse scoring as in Python. In the following script a data frame is generated with column names (i.e., columnNames,’Q1′ to ‘Q6’) and some data is generated using replicate and sample (100 responses, on the 6 questions). After that you will find two methods, that are pretty much the same, for reversing the can be found. The methods only differ in how the columns are selected. The first are select based on the index of the column and the second select based on the column names to be reversed (might be preferable if you know the names of columns but not the indices).