[R] Removing rows in a data frame containing string in rownames

Steven Yen syen04 at gmail.com
Mon Nov 17 03:31:25 CET 2014


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



More information about the R-help mailing list