- No class on Thursday (9/18) or Friday (9/19).
Patrick D. Schloss, PhD (microbialinformatics.github.io)
Department of Microbiology & Immunology
x <- pi
y <- 2
z <- -3
office <- "1520A MSRB I"
grade <- "A"
genome <- "ATGCATCGTCCCGT"
x <- TRUE
y <- FALSE
!x # NOT operator
x && y # AND operator
x & y # bitwise AND operator (vectors)
x || y # OR operator
x | y # bitwise OR operator (vectors)
x == y # is equal operator
x != y # is not equal operator
x <- 5
y <- 3
x > y # greater than operator
x >= y # greater than or equal to operator
x < y # less than operator
x <= y # less than or equal tooperator
x == y # is equal to operator
x != y # is not equal to operator
x <- "ATG"
y <- "CCC"
x > y # greater than operator
x >= y # greater than or equal to operator
x < y # less than operator
x <= y # less than or equal tooperator
x == y # is equal to operator
x != y # is not equal to operator
as.numeric(x)
as.logical(x)
as.character(x)
c()
, :
, rep()
, seq()
. Here are several examples:19:55 # list the values from 19 to 55 by ones
c(1,2,3,4) # concatenate 1, 2, 3, 4, 5 into a vector
rep("red", 5) # repeat "red" five times
seq(1,10,by=3) # list the values from 1 to 10 by 3's
seq(1,10,length.out=20) # list 20 evenly spaced elements from 1 to 10
seq(1,10,len=20) # same thing; arguments of any function can be
c(rep("red", 5), rep("white", 5), rep("blue", 5))
rep(c(0,1), 10)
countToTen <- 1:10
countToTen <- 1:10
length(countToTen)
countToTen
countToTen^2
countToTen > 5
typeof(countToTen)
is.vector(countToTen)
code <- c("A", "T", "G", "C")
code[2] # get the second element
code[0] # errr...
code[-1] # remove the first element
code[c(1,2)] # get the first and second elements
code[code > "M"] # get any element greater than "M"
code[length(code)]
z <- numeric(5) # This creates a numerical vector with 5 zeros
z[3] <- 10
z
z[1:3] <- 5
z
z[10] <- pi # NA's are inserted between 5 and 9
z[4] <- "R rocks!" # everything changes to a character
t <- character(5)
t[4] <- "DNA rocks!"
v <- numeric(0)
v["A"] <- 1.23498
v["T"] <- 2.2342
v["C"] <- 3
v["G"] <- 4
v["A"]
v[["A"]] # strips the name associated with value 1
v2 <- c(A=1.23498,T=2.2342,C=3,G=4)
names(v)
names(v) <- c("A", "B", "C", "D")
names(v) <- NULL # this removes names attribute
z <- runif(10) #generates a vector with 10 random numbers in it
z
sort(z) #sort the vector
order(z) #get the correct order of the elements in the vector
#sort a vector, matrix, data frame using the order command
o <- order(z)
z[o]