Skip to content
Prev 279354 / 398506 Next

Subsetting a data frame

does this do what you want:
+ 2, 1.3, 3), test2 = c(56L, 27L, 58L, 2L), test3 = c(1.1, 28,
+ 9, 1.2)), .Names = c("ind", "test1", "test2", "test3"), class =
+ "data.frame", row.names = c(NA,
+ -4L))
+     pat <- paste("^(", paste(inc, collapse = "|"), ")", sep = '')
+     patex <- paste(exc, collapse = "|")
+     isMatch <- apply(obj, 1, function(x) any(grepl(pat, x)))
+     notMatch <- !apply(obj, 1, function(x) any(grepl(patex, x)))
+     obj[isMatch & notMatch,]
+ }
ind test1 test2 test3
1 ind1   1.0    56   1.1
2 ind2   2.0    27  28.0
3 ind3   1.3    58   9.0
4 ind4   3.0     2   1.2
ind test1 test2 test3
2 ind2     2    27    28

        
On Mon, Dec 5, 2011 at 6:32 AM, natalie.vanzuydam <nvanzuydam at gmail.com> wrote: