1 1 1 1 1
> $ v2 : Factor w/ 4 levels "0","1","2","4": 1 4 2 1 1 2 2 2 3 1
> $ v3 : Factor w/ 4 levels "0","1","2","3": 1 1 1 2 2 1 3 3 4 1
> $ v4 : Factor w/ 4 levels "0","2","
Hello,
A logical index seems right. (And even intuitive?)
Create an index based on the conditions, multiplying 0/1 (FALSE/TRUE) by
the condition number. If all conditions are false, the index will be 0.
Then use ifelse() to update 'code'.
new_values <- c(1, 5, 10)
i <- apply(phdf[-6], 1, fun
Hi Phillip,
The following seems to do what you want:
phdf<-read.table(text="v1 v2 v3 v4 v5 code
0 0 0 0 01
1 4 0 0 01
1 1 0 0 01
1 0 1 0 01
2 0 1 0 01
0 1 0 0 01
0 1 2 0 01
0 1 2 3 01
0 2 3 4 41
0 0 0 2 31",
With the snippet of data below Iām trying to do an if/then type of thing:
row 1 ā if all five variables equal 0 then code equals 1;
row 3 ā if v1 = 1 and v2 = 1 then code = 5;
row 7 ā if v1 = 0 and v2 = 1 and v3 = 2 then code = 10
There are 24 codes in the complete database.
v1 v2
4 matches
Mail list logo