Skip to content
Prev 110313 / 398500 Next

Multiple conditional without if

Matthias,

According to the logic,

New matrix which is basically the old one except for all
entries which have a 4 in the 5 column AND a 1 in the 6th column

newmatrix <- oldmatrix[ (oldmatrix[,5]!=4 & oldmatrix[,6]!=1) , ]

---

newmatrix <- oldmatrix[ !(oldmatrix[,5]==4 & oldmatrix[,6]==1) , ]

by,

Felipe

-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of bunny ,
lautloscrew.com
Sent: Tuesday, February 27, 2007 1:25 PM
To: r-help at stat.math.ethz.ch
Subject: [R] Multiple conditional without if


Dear all,

i am stuck with a syntax problem.

i have a matrix which has about 500 rows and 6 columns.
now i want to kick some data out.
i want create a new matrix which is basically the old one except for all
entries which have a 4 in the 5 column AND a 1 in the 6th column.

i tried the following but couldn?t get a new matrix, just some wierd  
errors:

newmatrix=oldmatrix[,2][oldmatrix[,5]==4]&&oldmatrix[,2][oldmatrix[,6] 
==1]

all i get is:
numeric(0)

does anybody have an idea how to fix this one ?

thx in advance

matthias