Re: [R] Help on efficiency/vectorization

2009-08-27 Thread Steven Kang
> > fortune("parse") > > If the answer is parse() you should usually rethink the question. > -- Thomas Lumley >R-help (February 2005) > > > So please use one of the other answers given in the thread... > > >MO> --- On Thu, 27/8/09

Re: [R] Help on efficiency/vectorization

2009-08-27 Thread Martin Maechler
the other answers given in the thread... MO> --- On Thu, 27/8/09, Steven Kang wrote: >> From: Steven Kang >> Subject: [R] Help on efficiency/vectorization >> To: r-help@r-project.org >> Received: Thursday, 27 August, 2009, 4:13 PM >>

Re: [R] Help on efficiency/vectorization

2009-08-27 Thread Henrique Dallazuanna
Try this also: lapply(apply(x == 1, 2, which), names) On Thu, Aug 27, 2009 at 3:13 AM, Steven Kang wrote: > Dear R users, > > I am trying to extract the rownames of a data set for which each columns > meet a certain criteria. (condition - elements of each column to be equal > 1) > > I have the c

Re: [R] Help on efficiency/vectorization

2009-08-27 Thread jim holtman
try this: > x <- as.data.frame(matrix(round(runif(50),0),nrow=5)) > rownames(x) <- letters[1:dim(x)[1]] > x V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 a 0 0 1 0 0 1 0 0 0 1 b 1 0 0 0 1 1 1 1 0 0 c 0 1 0 1 0 0 0 0 1 0 d 0 1 0 0 0 1 0 0 1 1 e 0 0 1 1 0 1 1 0

Re: [R] Help on efficiency/vectorization

2009-08-26 Thread Moshe Olshansky
You can do for (i in 1:ncol(x)) {names <- rownames(x)[which(x[,i]==1)];eval(parse(text=paste("V",i,".ind<-names",sep="")));} --- On Thu, 27/8/09, Steven Kang wrote: > From: Steven Kang > Subject: [R] Help on efficiency/vectorization > To:

Re: [R] Help on efficiency/vectorization

2009-08-26 Thread Gerrit Eichner
Hi, Steven, try lapply( x, function( v) rownames(x)[ v == 1]) or lapply( x, function( v, rn) rn[ v == 1], rn = rownames( x))) which is faster. Regards -- Gerrit - AOR Dr. Gerrit Eichner Mathematical Institute

[R] Help on efficiency/vectorization

2009-08-26 Thread Steven Kang
Dear R users, I am trying to extract the rownames of a data set for which each columns meet a certain criteria. (condition - elements of each column to be equal 1) I have the correct result, however I am seeking for more efficient (desire vectorization) way in implementing such problem as it can