[R] how to return indexes
Roger Bivand
Roger.Bivand at nhh.no
Thu Sep 5 11:16:24 CEST 2002
On Thu, 5 Sep 2002, demolombe wrote:
> Hello,
>
> I wonder how to retreive indexes of data (and not data themseleves)
>
> example: a vector x<-c(10,20,30,40,50,60)
> a filter: f <- x>30 does retreive : 40,50,60
> f <- x[x>30] retreive
> false,false,false,true,true,true
>
> i would retreive the indexes: 4,5,6 because the 4th, 5th and 6th values
> were selected
>
> (this easy with matlab, but with R I know only sort(..., index.return=TRUE)
> which does that
>
which() ?
> x<-c(10,20,30,40,50,60)
> f <- x[x>30]
> f
[1] 40 50 60
> f <- which(x>30)
> f
[1] 4 5 6
>
Roger
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Breiviksveien 40, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 93 93
e-mail: Roger.Bivand at nhh.no
and: Department of Geography and Regional Development, University of
Gdansk, al. Mar. J. Pilsudskiego 46, PL-81 378 Gdynia, Poland.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list