Hi could yelp me with this
Suppose that we have the following matrix
m1<-matrix(c("a","e","a","i","o","u","i","1","2","3","4","5","6","7"),
ncol=2)
m2<-c("a","i")
m1
[,1] [,2]
[1,] "a" "1"
[2,] "e" "2"
[3,] "a" "3"
[4,] "i" "4"
[5,] "o" "5"
[6,] "u" "6"
[7,] "i" "7"
I want to obtain a new matrix with the rows from m1 where values of m2 are
present
for instance
[,1] [,2]
[1,] "a" "1"
[3,] "a" "3"
[4,] "i" "4"
[7,] "i" "7"
Bets Regards
--
Alberto Lora Michiels
Rue du Progrès, 6B
7860 Lessines
GSM 32(0)496659457
[[alternative HTML version deleted]]
Is this what you want:> m1<-matrix(c("a","e","a","i","o","u","i","1","2","3","4","5","6","7"),+ ncol=2)> m2<-c("a","i") > m1[,1] [,2] [1,] "a" "1" [2,] "e" "2" [3,] "a" "3" [4,] "i" "4" [5,] "o" "5" [6,] "u" "6" [7,] "i" "7"> m1[m1[,1] %in% m2,][,1] [,2] [1,] "a" "1" [2,] "a" "3" [3,] "i" "4" [4,] "i" "7">On Mon, Jul 20, 2009 at 7:06 AM, Alberto Lora M<albertoloram at gmail.com> wrote:> Hi could yelp me with this > > Suppose that we have the following matrix > > ?m1<-matrix(c("a","e","a","i","o","u","i","1","2","3","4","5","6","7"), > ncol=2) > m2<-c("a","i") > ?m1 > ? ? [,1] [,2] > [1,] "a" ?"1" > [2,] "e" ?"2" > [3,] "a" ?"3" > [4,] "i" ?"4" > [5,] "o" ?"5" > [6,] "u" ?"6" > [7,] "i" ?"7" > > > > I want to obtain a new matrix with the rows from m1 where values of m2 are > present > > for instance > ? ? [,1] [,2] > [1,] "a" ?"1" > [3,] "a" ?"3" > [4,] "i" ?"4" > [7,] "i" ?"7" > > Bets Regards > > -- > Alberto Lora Michiels > Rue du Progr?s, ?6B > 7860 Lessines > GSM 32(0)496659457 > > ? ? ? ?[[alternative HTML version deleted]] > > > ______________________________________________ > 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. > >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
Dear Alberto, One way would be: m1[ m1[,1] %in% m2, ] See ?"%in%" for more details. HTH, Jorge On Mon, Jul 20, 2009 at 7:06 AM, Alberto Lora M <albertoloram@gmail.com>wrote:> Hi could yelp me with this > > Suppose that we have the following matrix > > m1<-matrix(c("a","e","a","i","o","u","i","1","2","3","4","5","6","7"), > ncol=2) > m2<-c("a","i") > m1 > [,1] [,2] > [1,] "a" "1" > [2,] "e" "2" > [3,] "a" "3" > [4,] "i" "4" > [5,] "o" "5" > [6,] "u" "6" > [7,] "i" "7" > > > > I want to obtain a new matrix with the rows from m1 where values of m2 are > present > > for instance > [,1] [,2] > [1,] "a" "1" > [3,] "a" "3" > [4,] "i" "4" > [7,] "i" "7" > > Bets Regards > > -- > Alberto Lora Michiels > Rue du Progrès, 6B > 7860 Lessines > GSM 32(0)496659457 > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@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. > >[[alternative HTML version deleted]]