Skip to content

how to do something like " subset(mat, ("col1">4 & "col2">4)) "

5 messages · Florence Combes, Peter Dalgaard, Andy Bunn +1 more

#
Florence Combes <fcombes at gmail.com> writes:
Well, subset has methods for vectors and data frames, so what happens
for matrices is basically that they get converted to vectors. I don't
know what gave you the idea of quoting the names, but 

"colb">4

is TRUE because numbers sort before letters!

Try something like

as.matrix(subset(as.data.frame(mat),colb>4 & colc>4))
#
Some thing like this?

mat <- matrix(1:9,3,3)
mat
mat[apply(mat[,2:3] > 4,1,all),]
# or less cryptically
foo <- mat[,2:3] > 4
bar <- apply(foo,1,all)
mat[bar,]

HTH, Andy

NB: No need to send this kind of message to r-devel
http://www.R-project.org/posting-guide.html
#
maybe something like this:

subset(mat, mat[, 2] > 4 & mat[, 3] > 4)


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Florence Combes" <fcombes at gmail.com>
To: <r-help at stat.math.ethz.ch>; <r-devel-request at stat.math.ethz.ch>
Sent: Friday, September 09, 2005 4:09 PM
Subject: [R] how to do something like " subset(mat, ("col1">4 & 
"col2">4)) "
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm