simple operation

this is how R does addition

12+6
## [1] 18

this is how we store variables, going to store days of the week for example:

days<- c("Monday","Tuesday","WEDNESDAY", "TGURSDAY","FRIDAY", "SATURDAY","SUNDAY")

#LETS FIND 5TH ENTRY

days[5]
## [1] "FRIDAY"

find range of days

days[1:3]
## [1] "Monday"    "Tuesday"   "WEDNESDAY"

#how to find specific points

days[c(1,4,5,7)]
## [1] "Monday"   "TGURSDAY" "FRIDAY"   "SUNDAY"

#how to make a subset

weekdays<-days[1:5]
print(weekdays)
## [1] "Monday"    "Tuesday"   "WEDNESDAY" "TGURSDAY"  "FRIDAY"
weekdays
## [1] "Monday"    "Tuesday"   "WEDNESDAY" "TGURSDAY"  "FRIDAY"

functions

f*argument1,argument2,argument3) where f is the name of the function and the arguments are the different conditions of the functions to evaluate

exampleFunction <- function(x,y)
{c(x+1, y+10)}

exampleFunction(2,4)
## [1]  3 14

example of built in functions

(exp(2))
## [1] 7.389056
#how to do tangents
tan(2)
## [1] -2.18504

#logs log(12)

log(x=12, base = 4) log(12,4)

#Data structures #array function

months <-array(c(“jan”,“feb”,“mar”,“apr”,“may”,“june”,“july”,“aug”,“sept”,“oct”,“nov”,“dec”), dim=c(3,4)) #compared to simple list function months1 <- c(“jan”,“feb”,“mar”,“apr”,“may”,“june”,“july”,“aug”,“sept”,“oct”,“nov”,“dec”)

months1

#how to pull from an array

months[2,3]

#lets start a matrix

months2 <- matrix(data=c(“jan”,“feb”,“mar”,“apr”,“may”,“june”,“july”,“aug”,“sept”,“oct”,“nov”,“dec”), nrow=3,ncol=4)

months2

#making a 3d array

array3d <-array(c(2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36), dim =c(3,3,2))

print(array3d)

array3d[1,3,2]

#if you want to pull entire row or column array3d[2, ,1]

#list and data frames

HSPA1A <- list(gene=“HSPA1A”, amino.acids = 641, nucleotides = 2400) print(HSPA1A)

#SELECT for one category

HSPA1A\(amino.acids HSPA1A\)nucleotides #lets create 3 list and combine them in a data frame gene <- c(“HSPA4”, “HSPA5”, “HSPA8”,“HSPA9”,“HSPA1A”,“HSPA1B”) nucleotides <- c(54537, 6491, 4648, 21646, 2400, 2517) aminoAcids <- c(840, 654, 493, 679, 641, 641)

HSPs <- data.frame(gene, nucleotides, aminoAcids) #lets pull out just the genes/nucleotides from the data frame

HSPs\(gene HSPs\)nucleotides #lets find the specific amnio acid count HSPs\(aminoAcids[HSPs\)gene == “HSPA8”]

#object classes print(gene) print(HSPs) class(HSPs\(gene) class(HSPs\)nucleotides) HSPs$nucleotides

x <- 15 + 38 x

class(x) z <- as.character(c(1, 2, 3, 4, 5, 6)) z class(z) y <- as.character(c(9, 8, 7, 6, 5, 4)) z2 <- c(1, 2, 3, 4, 5, 6) y2 <- c(9, 8, 7, 6, 5, 4) z2 + y2 class(z2) class(HSPs)

y <- as.numeric(y) class(y)

#modules and formulas # y-x1 + x2

dataset <- iris #lets look at the top few rows

head(dataset) #lets look at the bottom few rows

tail(dataset)

dataset #lets look at total number of rows in dataset

nrow(dataset) #lets look at the total number of columns

ncol(dataset)

#lets look at simple linear model

petals.lm <-lm(formula = Petal.Length ~ Petal.Width, data = dataset)

petals.lm

summary(petals.lm)

#charts and graphs

names(iris)

hist(iris$Sepal.Length)

#lets increase the number of bins in our histogram

hist(iris$Sepal.Length, breaks = 25)

#lets add some labels

hist(iris$Sepal.Length, breaks = 25, xlab = “sepal length”, main = “sepal length frequnecy”)

plot(iris\(Sepal.Length ~ iris\)Sepal.Width, xlab= “sepal length”, ylab = “sepal width”)

library(lattice)

#lets do lattice dot plot

dotplot(Sepal.Width ~ Sepal.Length|Species, data = iris)

#lets use a lattice dotp;lot to look at lenght vs width

dotplot(Petal.Length ~ Petal.Width|Species, data = dataset)