> > 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
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
>>
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
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
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:
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
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
7 matches
Mail list logo