Thank you Bill and Dennis. grepl worked great. However, for reason I am not figuring out, the code worked as I included the procedure (subroutine) with a source command, viz.,
source("z:\\R\\mylib\\me.R") Compiling the routine into a library/package, as I always do, then the command got ignored. Hmm... Steven At 10:22 PM 11/16/2014, William Dunlap wrote: >Try grepl() to do pattern matching in strings. � ("%in%" checks for >equality.) � E.g., using your original 'out' do >� � out[ !grepl("sex|rating", rownames(out), ] >to get all but the rows whose names contain the character sequences >"sex" or "rating". > >Bill Dunlap >TIBCO Software >wdunlap <http://tibco.com>tibco.com > >On Sun, Nov 16, 2014 at 6:31 PM, Steven Yen ><<mailto:sye...@gmail.com>sye...@gmail.com> wrote: >I like to remove from a data frame rows with >labels containing certain string, e.g., "sex" >and "rating". Below is a list of the data frame >and my failed attempt to the rows. Any clues? Thanks. > > > out >� � � � � � � � � est� � � se� � � t� � � p disc >p.(Intercept) 26.430 13.605 1.943 0.053 >p.sex� � � � � 3.502� 3.930 0.891 0.373 * >p.children� � � 3.693� 4.521 0.817 0.414 * >p.occu� � � � � 0.740� 1.116 0.663 0.508 >p.rating� � � -7.897� 1.331 5.933 0.000 >c.(Intercept)� 1.861� 0.965 1.929 0.054 >c.sex� � � � � 0.221� 0.249 0.889 0.374 * >c.children� � � 0.234� 0.289 0.810 0.418 * >c.occu� � � � � 0.052� 0.079 0.663 0.508 >c.rating� � � -0.556� 0.102 5.451 0.000 >u.(Intercept)� 1.943� 1.017 1.910 0.057 >u.sex� � � � � 0.221� 0.248 0.888 0.375 * >u.children� � � 0.229� 0.276 0.827 0.409 * >u.occu� � � � � 0.054� 0.082 0.663 0.508 >u.rating� � � -0.581� 0.109 5.331 0.000 > > > out<-subset(out,!(names(out) %in% c("sex","rating"))) > > out >� � � � � � � � � est� � � se� � � t� � � p disc >p.(Intercept) 26.430 13.605 1.943 0.053 >p.sex� � � � � 3.502� 3.930 0.891 0.373 * >p.children� � � 3.693� 4.521 0.817 0.414 * >p.occu� � � � � 0.740� 1.116 0.663 0.508 >p.rating� � � -7.897� 1.331 5.933 0.000 >c.(Intercept)� 1.861� 0.965 1.929 0.054 >c.sex� � � � � 0.221� 0.249 0.889 0.374 * >c.children� � � 0.234� 0.289 0.810 0.418 * >c.occu� � � � � 0.052� 0.079 0.663 0.508 >c.rating� � � -0.556� 0.102 5.451 0.000 >u.(Intercept)� 1.943� 1.017 1.910 0.057 >u.sex� � � � � 0.221� 0.248 0.888 0.375 * >u.children� � � 0.229� 0.276 0.827 0.409 * >u.occu� � � � � 0.054� 0.082 0.663 0.508 >u.rating� � � -0.581� 0.109 5.331 0.000 > >______________________________________________ ><mailto:R-help@r-project.org>R-help@r-project.org mailing list ><https://stat.ethz.ch/mailman/listinfo/r-help>https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide ><http://www.R-project.org/posting-guide.html>http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. > [[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.