- A new homework has been posted and is due on November 22nd
- work with a partner
- no more than one explicit loop
- Will have lab period on Friday
- Read Chapters 11 in TAoRP for background material on what is discussed today
Patrick D. Schloss, PhD (microbialinformatics.github.io)
Department of Microbiology & Immunology
rev("abcdef")
paste(rev(unlist(strsplit("abcdef", ""))), collapse="")
sprintf
i <- 8
sprintf("the square of %d is %d", i, i^2)
## [1] "the square of 8 is 64"
sprintf("the square root of %d is %6.2f", i, sqrt(i))
## [1] "the square root of 8 is 2.83"
sprintf("%d times 1e6 is %.3e", i, i * 1e6)
## [1] "8 times 1e6 is 8.000e+06"
%s
reserves the place for an string%d
reserves the place for an integer%f
reserves the place for an decimal number%e
reserves the place for an number in scientific notation%f
and %e
the format is %m.n
. n
indicates the number of values to the right of the decimal place to include and m
indicates the total number of spaces to allot the stringformat(x, trim = FALSE, digits = NULL, nsmall = 0L,
justify = c("left", "right", "centre", "none"),
width = NULL, na.encode = TRUE, scientific = NA,
big.mark = "", big.interval = 3L,
small.mark = "", small.interval = 5L,
decimal.mark = ".", zero.print = NULL,
drop0trailing = FALSE, ...)`
x
is a numbertrim
is whether to right justify numbers to a common widthdigits
is the maximum number of significant digitsnsmall
is the minimum number of digits to the right of the decimal letters[1:5]
## [1] "a" "b" "c" "d" "e"
LETTERS[1:5]
## [1] "A" "B" "C" "D" "E"
toupper(letters[1:5])
## [1] "A" "B" "C" "D" "E"
tolower(LETTERS[1:5])
## [1] "a" "b" "c" "d" "e"
grep(pattern, x)
- "Get Regular ExPression"grep("A", c("ATA", "CCC", "CTA"))
## [1] 1 3
grep("G", c("ATA", "CCC", "CTA"))
## integer(0)
grep
tells you which elements of x have the patterngrepl(pattern, x)
- "Get Regular ExPression" logic-basedgrep("A", c("ATA", "CCC", "CTA"))
## [1] 1 3
grep("G", c("ATA", "CCC", "CTA"))
## integer(0)
grepl
tells you whether or not each element of x ahs the patternregexpr(pattern, x)
- identify the starting position of the pattern in xregexpr("ATG", "CTATGCATGC")
## [1] 3
## attr(,"match.length")
## [1] 3
## attr(,"useBytes")
## [1] TRUE
gregexpr(pattern, x)
- identify the starting position of the pattern throughout x ~ globalgregexpr("ATG", "CTATGCATGC")
## [[1]]
## [1] 3 7
## attr(,"match.length")
## [1] 3 3
## attr(,"useBytes")
## [1] TRUE
sub(pattern, replacement, x)
- SUBstitute the PATTERN with the REPLACEMENTsub("T", "U", "CTATGCATGC")
## [1] "CUATGCATGC"
gsub(pattern, replacement, x)
- replaces all instancesgsub("T", "U", "CTATGCATGC")
## [1] "CUAUGCAUGC"
gsub
?dna <- "CTATGCATGC"
The complement should be GATACGTACG
chartr(findChars, replaceChars, x)
chartr("T", "A", "CTATGCATGC")
## [1] "CAAAGCAAGC"
chartr("TA", "AT", "CTATGCATGC")
## [1] "CATAGCTAGC"
chartr("TACG", "ATGC", "CTATGCATGC")
## [1] "GATACGTACG"
grep("g", "ATGCATGC")
## integer(0)
grep("g", "ATGCATGC", ignore.case=T)
## [1] 1
grep("^ATG", vectorOfGenes)
grep("TAA$", vectorOfGenes)
grep("TAA$|TAG$", vectorOfGenes)
metadata <- read.table(file="wild.metadata.txt", header=T)
head(metadata)
## Group Date ET Station SP Sex Age Repro Weight Ear
## 1 5_25m3 5_25 3 BB18 PL M J ABD 7.5 13
## 2 5_25m4 5_25 4 K19 PL M A SCR 16.0 15
## 3 5_26m1 5_26 1 A12 PL F A NE 19.5 14
## 4 5_26m9 5_26 9 M9 PL F A NE 25.0 13
## 5 5_31m11 5_31 11 F2 PMG F J NT 16.0 18
## 6 5_31m2 5_31 2 CC4 PL M SA ABD 15.0 14
Date
column is the date that the mice were captured in M_DD
format. Can you convert this column into "Month Day, Year" format? Assume the year was 2011.