Hi, I have a matrix.>a<-cbind(c("a","b","a"),c(4,3,6))[,1] [,2] [1,] "a" "4" [2,] "b" "3" [3,] "a" "6" I want to remove rows in matrix a whose first column has frequency less than 2. in about example matrix a becomes [,1] [,2] [1,] "a" "4" [2,] "a" "6" [[alternative HTML version deleted]]
Dear jayuan2008, See ?subset. If I understand your description below, something like this could do the job: a1<-data.frame(x=c("a","b","a","b","a"),y=c(4,3,6,1,2)) subset(a1,y>2) x y 1 a 4 2 b 3 3 a 6 BTW, I think that the final result you described in your post is incorrect. HTH, Jorge On Sun, Aug 31, 2008 at 2:19 AM, Yuan Jian <jayuan2008@yahoo.com> wrote:> Hi, > > I have a matrix. > >a<-cbind(c("a","b","a"),c(4,3,6)) > [,1] [,2] > [1,] "a" "4" > [2,] "b" "3" > [3,] "a" "6" > > I want to remove rows in matrix a whose first column has frequency less > than 2. > in about example matrix a becomes > [,1] [,2] > [1,] "a" "4" > [2,] "a" "6" > > > > > > [[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]]
DF<-cbind(c("a","b","a"),c(4,3,6)) DF[(DF[,1] %in% names(which(table(DF[,1]) >= 2))),] On Sun, Aug 31, 2008 at 2:19 AM, Yuan Jian wrote:> Hi, > ? > I have a matrix. >> a<-cbind(c("a","b","a"),c(4,3,6)) > ???? [,1] [,2] > [1,] "a"? "4" [2,] "b"? "3" [3,] "a"? "6" > I want to remove rows in matrix a whose first column has frequency > less than 2. > in about example matrix a becomes > ???? [,1] [,2] > [1,] "a"? "4" [2,] "a"? "6" > > > > [[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.
See ?ave and try this: a[as.numeric(ave(a[,1], a[,1], FUN = length)) > 1, ] On Sun, Aug 31, 2008 at 2:19 AM, Yuan Jian <jayuan2008 at yahoo.com> wrote:> Hi, > > I have a matrix. >>a<-cbind(c("a","b","a"),c(4,3,6)) > [,1] [,2] > [1,] "a" "4" > [2,] "b" "3" > [3,] "a" "6" > > I want to remove rows in matrix a whose first column has frequency less than 2. > in about example matrix a becomes > [,1] [,2] > [1,] "a" "4" > [2,] "a" "6" > > > > > > [[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. > >