[R] finding dedicated indexes?

Kaspar Pflugshaupt pflugshaupt at cirsium.ethz.ch
Tue Mar 20 17:31:33 CET 2001


On Tuesday 20 March 2001 16:57, Thomas Bruns wrote:
> Hi,
>
> I've got a matrix of two columns, say:
> > d <- t(array(1:20,dim=c(2,10)))
> > d
>
>       [,1] [,2]
>  [1,]    1    2
>  [2,]    3    4
>  [3,]    5    6
>  [4,]    7    8
>  [5,]    9   10
>  [6,]   11   12
>  [7,]   13   14
>  [8,]   15   16
>  [9,]   17   18
> [10,]   19   20
>
> now I need those values from column #2 where column #1 is equal to
>
> certain values. eg.:
> > i <- c(13,5,19)
>
> The following doesn't work but you may get the idea:
> >print( d[ d[,1]==i ,2])

Try

  print( d[d[,1] %in% i ,2])

Cheers

Kaspar

-- 


Kaspar Pflugshaupt
Geobotanical Institute
ETH Zurich, Switzerland

http://www.geobot.umnw.ethz.ch
mailto:pflugshaupt at geobot.umnw.ethz.ch
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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