[R] How to get the rowindices without using which?
Dimitris Rizopoulos
dimitris.rizopoulos at med.kuleuven.be
Mon Sep 26 10:51:41 CEST 2005
try this:
dat <- iris[sample(1:nrow(iris), 10), ]
dat
match(rownames(dat), rownames(iris))
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
----- Original Message -----
From: "Martin Lam" <tmlammail at yahoo.com>
To: "R" <r-help at stat.math.ethz.ch>
Sent: Monday, September 26, 2005 10:37 AM
Subject: [R] How to get the rowindices without using which?
> 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
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
More information about the R-help
mailing list