[R] How to get the rowindices without using which?

Spencer Graves spencer.graves at pdf.com
Thu Sep 29 17:50:51 CEST 2005


	  I'm  not certain what you are asking.  Consider the following:

set.seed(1)
(irows <- sample(1:nrow(iris), 10))
iris[irows,]

	  If you want more than this, PLEASE do read the posting guide! 
"www.R-project.org/posting-guide.html".  I believe that people who 
follow the posting guide generally get quicker and better answers than 
those who don't.

	  spencer graves

Martin Lam wrote:

> Hi,
> 
> I was wondering if it is possible to get the
> rowindices without using the function "which" because
> I don't have a restriction criteria. Here's an example
> of what I mean:
> # take 10 randomly selected instances
> iris[sample(1:nrow(iris), 10),]
> 
> # output
>     Sepal.Length Sepal.Width Petal.Length Petal.Width 
>   Species
> 76           6.6         3.0          4.4         1.4
> versicolor
> 105          6.5         3.0          5.8         2.2 
> virginica
> 131          7.4         2.8          6.1         1.9 
> virginica
> 79           6.0         2.9          4.5         1.5
> versicolor
> 69           6.2         2.2          4.5         1.5
> versicolor
> 42           4.5         2.3          1.3         0.3 
>    setosa
> 25           4.8         3.4          1.9         0.2 
>    setosa
> 129          6.4         2.8          5.6         2.1 
> virginica
> 60           5.2         2.7          3.9         1.4
> versicolor
> 80           5.7         2.6          3.5         1.0
> versicolor
> 
> What I want to get are their rownumbers: 76, 105, 131,
> 79, 69, 42, 25, 129, 60, 80.
> 
> Thanks in advance,
> 
> Martin
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

-- 
Spencer Graves, PhD
Senior Development Engineer
PDF Solutions, Inc.
333 West San Carlos Street Suite 700
San Jose, CA 95110, USA

spencer.graves at pdf.com
www.pdf.com <http://www.pdf.com>
Tel:  408-938-4420
Fax: 408-280-7915




More information about the R-help mailing list