Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in R Programming by (120 points)
I'm importing participant data from an Excel spreadsheet and then am trying to change the values of certain cells in one column of the dataframe based on a criteria in another column (in the form of a nested if - else if statement inside an if statement).
However, I get the error message 'Error in if (.) Reverse_keyed == 1 else { : argument is not interpretable as logical'. 'Reverse_keyed' is the column heading - where the value is 1 (the other possible value it takes in the filtered cells is 0), I am trying to change the values in the 'response_responseV' column, depending on the values in those cells. 'D' is the master frame with each subject's data and variables.

questionnaire = D %>%
  filter(!is.na(response_responseV), is.na(response_responseS))  %>%
         if (Reverse_keyed == "1") {
          if (response_responseV == "1") {
            response_responseV == "7"
          } else if (response_responseV == "2") {
              response_responseV == "6"
            } else if (response_responseV == "3") {
                response_responseV == "5"
              } else if (response_responseV == "5") {
                  response_responseV == "3"
              } else if (response_responseV == "6") {
                  response_responseV == "2"
              } else if (response_responseV == "7") {
                  response_responseV == "1"
                }
        }     

Can anyone help this R dummy to resolve this issue or at least try and guide me to see how I can resolve it? It seems that it may be trying to interpret Reverse_keyed as logical rather than numerical. Apologies if anything's not clear. Let me know if you need further information or context.

Please log in or register to answer this question.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.7k users

Browse Categories

...