Extracts (possibly overlapping) rows provided both a pattern or index position to match and a range specifying how many rows before and after the matched row.
getMyRows(data, pattern, range, isNumeric = TRUE)
data | The input |
---|---|
pattern | Either the pattern to match in the |
range | A vector indicating the range of rows you want to extract (in
the form of |
isNumeric | Logical. Is |
A list
of data.frame
s with the relevant rows
extracted.
http://stackoverflow.com/a/13155669/1270695
Ananda Mahto
set.seed(1) dat1 <- data.frame(ID = 1:25, V1 = sample(100, 25, replace = TRUE)) rownames(dat1) <- paste("rowname", sample(apply(combn(LETTERS[1:4], 2), 2, paste, collapse = ""), 25, replace = TRUE), sprintf("%02d", 1:25), sep = ".") getMyRows(dat1, c(2, 10), -3:2)#> [[1]] #> ID V1 #> rowname.AB.01 1 68 #> rowname.BC.02 2 39 #> rowname.AD.03 3 1 #> rowname.CD.04 4 34 #> #> [[2]] #> ID V1 #> rowname.CD.07 7 14 #> rowname.BC.08 8 82 #> rowname.BC.09 9 59 #> rowname.BC.10 10 51 #> rowname.AC.11 11 97 #> rowname.BC.12 12 85 #>#> [[1]] #> ID V1 #> rowname.AB.01 1 68 #> rowname.BC.02 2 39 #> #> [[2]] #> ID V1 #> rowname.CD.04 4 34 #> rowname.AC.05 5 87 #> rowname.AC.06 6 43 #> #> [[3]] #> ID V1 #> rowname.AC.05 5 87 #> rowname.AC.06 6 43 #> rowname.CD.07 7 14 #> #> [[4]] #> ID V1 #> rowname.BC.10 10 51 #> rowname.AC.11 11 97 #> rowname.BC.12 12 85 #> #> [[5]] #> ID V1 #> rowname.BC.12 12 85 #> rowname.AB.13 13 21 #> rowname.CD.14 14 54 #> #> [[6]] #> ID V1 #> rowname.CD.14 14 54 #> rowname.AB.15 15 74 #> rowname.BC.16 16 7 #> #> [[7]] #> ID V1 #> rowname.BC.16 16 7 #> rowname.AB.17 17 73 #> rowname.CD.18 18 79 #> #> [[8]] #> ID V1 #> rowname.CD.18 18 79 #> rowname.AC.19 19 85 #> rowname.AD.20 20 37 #> #> [[9]] #> ID V1 #> rowname.AD.20 20 37 #> rowname.AC.21 21 89 #> rowname.CD.22 22 37 #> #> [[10]] #> ID V1 #> rowname.CD.23 23 34 #> rowname.AC.24 24 89 #> rowname.BD.25 25 44 #>#> [[1]] #> ID V1 #> rowname.BC.02 2 39 #> #> [[2]] #> ID V1 #> rowname.CD.04 4 34 #> rowname.AC.06 6 43 #> #> [[3]] #> ID V1 #> rowname.AC.05 5 87 #> rowname.CD.07 7 14 #> #> [[4]] #> ID V1 #> rowname.BC.10 10 51 #> rowname.BC.12 12 85 #> #> [[5]] #> ID V1 #> rowname.BC.12 12 85 #> rowname.CD.14 14 54 #> #> [[6]] #> ID V1 #> rowname.CD.14 14 54 #> rowname.BC.16 16 7 #> #> [[7]] #> ID V1 #> rowname.BC.16 16 7 #> rowname.CD.18 18 79 #> #> [[8]] #> ID V1 #> rowname.CD.18 18 79 #> rowname.AD.20 20 37 #> #> [[9]] #> ID V1 #> rowname.AD.20 20 37 #> rowname.CD.22 22 37 #> #> [[10]] #> ID V1 #> rowname.CD.23 23 34 #> rowname.BD.25 25 44 #>