Many thanks to all for resolving my issue!
On Thu, Aug 27, 2009 at 10:33 PM, Martin Maechler <
maech...@stat.math.ethz.ch> wrote:
> > "MO" == Moshe Olshansky
> > on Wed, 26 Aug 2009 23:36:22 -0700 (PDT) writes:
>
>MO> You can do
>MO> for (i in 1:ncol(x)) {names <-
> rownames(
> "MO" == Moshe Olshansky
> on Wed, 26 Aug 2009 23:36:22 -0700 (PDT) writes:
MO> You can do
MO> for (i in 1:ncol(x)) {names <-
rownames(x)[which(x[,i]==1)];eval(parse(text=paste("V",i,".ind<-names",sep="")));}
you can, but after install.packages("fortunes")
> require("f
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: r-help@r-project.org
> Received: Thursday, 27 August
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
6 matches
Mail list logo