Here we create a new column in our dataframe called “SDO1R” and tell R to take the SDO1 column and fill our new column with recoded data as we have specified in the quotes inside the recode() function.

numeric_data$SDO1R <- recode(numeric_data$SDO1, "1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else=NA")

compare the contents of the SDO1 column:

numeric_data$SDO1
##  [1] 5 6 7 7 7 7 3 7 7 3 7 5 2 5 7 7 7 3 7 1 7 7 6 7 4 1 7 7 2 7 7 3 4 7 7 4 7 1 7 2 5 4 7 2 7 7 7 3 7
## [50] 7 1 7 6 4 4 7 2 5 7 1 6 7 7 7 5 7 2 3 5 7 2 6 7 7 7 5 3 4 7 7 7 7 7 3 2 6 3 7 2
## 10 Levels:  {"ImportId":"QID440"} 1 2 3 4 5 6 ... An ideal society requires some groups to be on top and others to be on the bottom.

to the contents of the reversed column:

numeric_data$SDO1R
##  [1] 3 2 1 1 1 1 5 1 1 5 1 3 6 3 1 1 1 5 1 7 1 1 2 1 4 7 1 1 6 1 1 5 4 1 1 4 1 7 1 6 3 4 1 6 1 1 1 5 1
## [50] 1 7 1 2 4 4 1 6 3 1 7 2 1 1 1 3 1 6 5 3 1 6 2 1 1 1 3 5 4 1 1 1 1 1 5 6 2 5 1 6
## Levels: 1 2 3 4 5 6 7

It worked! So, we repeat the process with each of the columns that need reverse coding:

numeric_data$SDO2R <- recode(numeric_data$SDO2,"1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else=NA")
numeric_data$SDO5R <- recode(numeric_data$SDO5,"1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else=NA")
numeric_data$SDO6R <- recode(numeric_data$SDO6,"1=7; 2=6; 3=5; 4=4; 5=3; 6=2; 7=1; else=NA")

Now, in order to analyze this variable properly and effectively, we collect all the reversed columns and all the original versions of the non-reversed columns into a single data frame:

SDO <- data.frame(numeric_data$SDO1R, numeric_data$SDO2R, 
                  numeric_data$SDO3, numeric_data$SDO4, 
                  numeric_data$SDO5R, numeric_data$SDO6R,
                  numeric_data$SDO7, numeric_data$SDO8)

With this dataframe, we can calculate both Cronbach’s Alpha and the mean scores for this scale.