Skip to content

Commit 684c9c4

Browse files
authored
Create selecting columns based on string match
1 parent 682d129 commit 684c9c4

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# selecting certain columns that contain a string of characters
2+
# eg I have an OTU table and my sample names correspond to treatment
3+
# and timepoint. I can select all the samples from a certain treatment
4+
5+
require(dplyr)
6+
# eg my samples names from my controls all contain the prefix "Tmt1" eg Tmt1_t0_repA
7+
8+
tmt1 <- select(fullDataSet, starts_with("Tmt1"))
9+
10+
# if I wanted to select based on time (which is in the middle of the string then change for 'contains'
11+
12+
timeZero <- select(fullDataSet, contains("t0"))
13+
14+
# or if i wanted to choose all replicate As from the dataset it would be ends_with()
15+
16+
repAs <- select(fullDataSet, ends_with("repA"))

0 commit comments

Comments
 (0)