2006/1/30, Ionut Florescu <[EMAIL PROTECTED]>:
>
> I don't know about rownames but
> x >= 0 gives you a vector of logical values True and false.
> If then you do
> c(1:length(x)) [x>=0]
> this gives the positions where the true happened, meaning your vector of
> values.


But also returns NA's, if present in 'X'. If you're really interested in
indices of matched condition, consider using 'which':
which(mydata$X>=0)
Anyway, if you're really interested in rownames instead of numerical
indices, you have various options. For example:
rownames(mydata)[which(mydata$X>=0)]
or, more compactly, as Chuck Cleland has suggested:
rownames(subset(mydata, X >=0))


Antonio, Fabio Di Narzo.

> Chuck Cleland wrote:
> > rownames(subset(mydata, X >=0))
> >
> > ?rownames
> >
> > Leaf Sun wrote:
> >
> >> Hi R-listers,
> >>
> >> I have a simple question about a data frame.
> >>
> >> I sorted a data set by one of the variable in some condition (eg.
> X>=0),  the followed is part of the achieved. I was wondering how can I get
> the row name, i. e.   (1202,  2077 , 2328,  3341,...  ) and save them as a
> vector.     Thanks!
> >>
> >>                        Tag  Species     X     Y Dbh3 Recr4 mort slope
> elevation aspect    SA   SR     dist1     dist2     dist3
> >> 1202    19103     316 856.0 430.3   21     4    1  9.87    151.42
> 60.08 25.38 1.02 0.2236068 0.7211103 1.3601471
> >> 2077    29893     316 935.4 482.7   28     4    1  5.66    137.28
> 13.86 25.14 1.01 0.6403124 0.8944272 1.0630146
> >> 2328    32989     316 910.7 301.5   12     4    1  8.07    137.69
> 86.16 25.26 1.01 0.3000000 1.2806248 1.3038405
> >> 3341    45198     316 975.2   2.4  144     4    1  2.95    121.10
> 173.60  0.00 0.00 0.5656854 1.2727922 1.3416408
> >> ...
> >>
> >> Regards,
> >>
> >> Leaf
> >>
> >>
> >>
> >>
> ------------------------------------------------------------------------
> >>
> >> ______________________________________________
> >> [email protected] mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> >>
> >
> >
> > ------------------------------------------------------------------------
> >
> > ______________________________________________
> > [email protected] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>

        [[alternative HTML version deleted]]

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Reply via email to