Skip to content
Prev 361069 / 398506 Next

if else condition - help

If the problems were somewhat less symmetric or  more complex this would be a method that could be easily generalized to a larger number of less "absolutely" symmetric intervals:

 k2 <- k
 k2[] <- findInterval(k2, c(-Inf, -1.5, 1.5, Inf) ) -2  
                                             # shifts the 1-3 values to -1 to 1
 k2
  C1 C2 C3 C4
A  0  0  0  0
B  1  0  0  0
C  0 -1  0  0
D -1  1 -1 -1

Using k2[] <- ... preserves the matrix structure
David Winsemius
Alameda, CA, USA