Hi all, I am trying to filter the element of a df that start with "TF", like this: alfa c(123221,"TF13124",41243,"TF1234",32414,"TF13124","TF14333",2134123,"TF1234") beta c("type_a","type_b","type_a","type_g","type_d","type_a","type_g","type_a","type_g") mydf = data.frame(alfa,beta) mydf tf = mydf[mydf$alfa %in% "TF",] Shouldn't the %in% operator to the trick here? Thanks in advance, Albert.
Albert Vilella wrote:> Hi all, > > I am trying to filter the element of a df that start with "TF", like > this: > > alfa > c(123221,"TF13124",41243,"TF1234",32414,"TF13124","TF14333",2134123,"TF1234") > beta > c("type_a","type_b","type_a","type_g","type_d","type_a","type_g","type_a","type_g") > mydf = data.frame(alfa,beta) > mydf > tf = mydf[mydf$alfa %in% "TF",] > > Shouldn't the %in% operator to the trick here?tf <- mydf[grep("^TF", as.character(mydf$alfa)),]> Thanks in advance, > > Albert. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
I think that you want to use 'grep' after converting the factors to characters:> tf = mydf[grep("TF", as.character(mydf$alfa)),] > tfalfa beta 2 TF13124 type_b 4 TF1234 type_g 6 TF13124 type_a 7 TF14333 type_g 9 TF1234 type_g>On 4/28/06, Albert Vilella <avilella@gmail.com> wrote:> > Hi all, > > I am trying to filter the element of a df that start with "TF", like > this: > > alfa > > c(123221,"TF13124",41243,"TF1234",32414,"TF13124","TF14333",2134123,"TF1234") > beta > > c("type_a","type_b","type_a","type_g","type_d","type_a","type_g","type_a","type_g") > mydf = data.frame(alfa,beta) > mydf > tf = mydf[mydf$alfa %in% "TF",] > > Shouldn't the %in% operator to the trick here? > > Thanks in advance, > > Albert. > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html >-- Jim Holtman Cincinnati, OH +1 513 646 9390 (Cell) +1 513 247 0281 (Home) What the problem you are trying to solve? [[alternative HTML version deleted]]
Reasonably Related Threads
- [PATCH 23/23] nvc0: implement support for maxwell texture headers
- [PATCH 23/23] nvc0: implement support for maxwell texture headers
- [PATCH 23/23] nvc0: implement support for maxwell texture headers
- accessing constants in model from controller.
- [PATCH 0/1] efi: DNS resolver