I am trying to recode a variable into another variable and while the package
'car' works well when it is only recoding A into B, I am not sure I can do
the same with recoding (A or C) into B. If i can use recode please advise on
how to. So i am using an if/else if conditions.

My sample dataset is below along with the code and the warning and results i
get.

TIA
Krishnan

#****Code****
attach(airport_survey)
if(AccessMode == 1 || AccessMode == 8 || AccessMode == 9) {
       airport_survey$amodecat <- 1
} else if (AccessMode == 2) {
       airport_survey$amodecat <- 2
} else if (AccessMode == 3 & rentalcat == 1 || AccessMode == 4 & rentalcat
== 1) {
        airport_survey$amodecat <- 3
} else if (AccessMode == 5) {
       airport_survey$amodecat <- 8
} else if (AccessMode == 6 || AccessMode == 14) {
       airport_survey$amodecat <- 9
} else if (AccessMode == 7) {
       airport_survey$amodecat <- 5
} else if (AccessMode == 10) {
       airport_survey$amodecat <- 7
} else if (AccessMode == 11 || AccessMode == 12) {
       airport_survey$amodecat <- 4
} else if (AccessMode == 13) {
       airport_survey$amodecat <- 6
} else if(AccessMode == 3 & rentalcat == 2 ||AccessMode == 4 & rentalcat ==
2) {
       airport_survey$amodecat <- 10
} else { # else statement here just to close out the condition
       airport_survey$amodecat <- 0
}


#*****dataset****

AccessMode RentalCat
4 2
4 1
4 2
3 1
3 2
14 1
1 1
2 1
8 1
9 1
10 1
11 1
12 1
13 1
6 1
5 1
7 2

# Warning + Results

Warning messages:
1: In if (AccessMode == 2) { :
  the condition has length > 1 and only the first element will be used
2: In if (AccessMode == 5) { :
  the condition has length > 1 and only the first element will be used
3: In if (AccessMode == 7) { :
  the condition has length > 1 and only the first element will be used
4: In if (AccessMode == 10) { :
  the condition has length > 1 and only the first element will be used
5: In if (AccessMode == 13) { :
  the condition has length > 1 and only the first element will be used

# After Running summary on the variable (it seems to only take the last if
condition)

   amodecat
 Min.   :10
 1st Qu.:10
 Median :10
 Mean   :10
 3rd Qu.:10
 Max.   :10

-- 
Krishnan Viswanathan
1101 High Meadow Dr
Tallahassee FL 32311

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to