I have a dataset with 90 responses to Likert Items that I would like to convert to numeric values. It is structured like the example here:
q6 <- c("Daily", "Never", "Often", "Very Often", "Daily")
q7 <- c("Never", "Never", "Often", "Often", "Daily")
q23 <- c("Daily", "Often", "Never", "Never", "Neutral")
q17 <- c("Important", "Important", "Very Important", "Neutral", "Not Important")
example <- cbind(q6, q7, q17, q23)
The responses to each question differ slightly, but are in the main either in the range of Strongly Disagree to Strongly Agree, Daily to Never, or Important to Not Important. Each of the responses to the 90 questions are in a separate column (labelled q1 > q90). I'd like to create new columns for set of responses with a numeric value that corresponds to the text response (Strong Agree (3) to Strongly Disagree (-3), via Neutral (0)). Like so
q6 <- c("Daily", "Never", "Often", "Very Often", "Daily")
n6 <- c(3,-3,1,2,3)
q17 <- c("Important", "Important", "Very Important", "Neutral", "Not Important")
n17 <- c(2,2,3,0,-3)
num_example <- cbind(q6, n6, q17, n17)
num_example
I've managed to get so far with the code below, which generates a new variable called n6 that matches the text responses in the existing q6 column, that I can then add to the existing data frame using cbind. My questions is: how would I automate this across the entire data frame of 90 questions without having to run the code below for each response (i.e. changing q6 to q7, then to q8, and so on).
n6 <- ifelse(example$q6=="Daily", 3,
ifelse(h16$q6=="",0,
ifelse(h16$q6=="Very Often", 2,
ifelse(h16$q6=="Often", 1,
ifelse(h16$q6=="Neither Rarely nor Often", 0,
ifelse(h16$q6=="Rarely", -1,
ifelse(h16$q6=="Very Rarely", -2,
ifelse(h16$q6=="Never", -3,5
))))))))
For further reference, columns q6:q12, then q23:30 have responses ranging from Daily to Never, as per the example above. Columns q17:q22 have responses ranging from Not Important to Very Important, Columns q49:q90 have responses that range from Strongly Agree to Strongly Disagree. I'm trying to find a smarter way of running the code below over the relevant columns (e.g. q6:12, q23:q30) in a way that generates a new data frame with numeric values in columns named n6:n16, n23:30, rather than having to run the code below 90 times!
Hope this is a clear explanation of the issue.
Thank you.