[R] Subsetting matrix with values from vector
Jorge Ivan Velez
jorgeivanvelez at gmail.com
Tue Sep 15 16:56:44 CEST 2009
Hi jorgusch,
First, do not call your data, "data" :-)
require(fortunes)
fortune('dog')
Here are two suggestions to do what you asked for:
# your data
id <- 1:5
idnew <- 3:10
# to get the indexes
id %in% idnew
# to get the id's matching the new vector
id[ id %in% idnew ]
# another way
intersect(id, idnew)
See ?"%in%" and ?intersect for more information.
HTH,
Jorge
On 9/15/09, jorgusch <hackl.schorsch at web.de> wrote:
>
> Hello,
>
> I have a large matrix (data), in which there is a column offerid. The values
> are numbers (lets say 1:5)
> There is another vector (idnew), which contains some of the offerids and
> many more (3:10).
>
> I want a subset of the matrix wiith only those rows, which match the
> criteria of the vector.
>
> How can I make it work?
>
> Thanks!
> --
> View this message in context:
> http://www.nabble.com/Subsetting-matrix-with-values-from-vector-tp25450905p25450905.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
HTH,
Jorge Ivan VELEZ, NHGRI USA
More information about the R-help
mailing list