0

I have a problem, I used fct_recode to change the text responses to numbers

data <- data %>% 
  mutate(sustainability_sq001 = fct_recode(sustainability_sq001,
  "1" = "Completely Disagree", 
  "2" = "Disagree", 
  "3" = "Somewhat Disagree", 
  "4" = "Somewhat Agree", 
  "5" = "Agree", 
  "6" = "Completely Agree"))

but R cannot calculate with it: Error in rowMeans(.): 'x' must be numeric

When I use: data$sustainability_sq001 <- as.numeric(data$sustainability_sq001) to change the numbers It changes the of my responses:

Before:

  sustainability_sq001 n
1                    5 31
2                    6 11
3                    3  6
4                    4 26
5                    1  5
6                    2  3

Option 5 had the most responses with 31, and R ranked it from 1-5 smh.

After:

  sustainability_sq001  n
1                    1 31
2                    2 11
3                    3  6
4                    4 26
5                    5  5
6                    6  3

R adjusted the responses to fit the ranking, which I do not want

r2evans
  • 108,754
  • 5
  • 72
  • 122
harry
  • 1
  • 2
    Welcome to SO, harry! Please make this question *reproducible*. Your code is good, please add sample *unambiguous* data using the output from `dput(head(x))`, since just showing the console rendering of a frame hides from us the factors and levels and such. Please also be clear about the intended output given that input. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. Thanks! – r2evans May 24 '22 at 13:09

0 Answers0