Â
These exercises are about the matrices sections of Introduction to R.
These exercises cover the matrices sections of Introduction to R.
Exercise 1
<- c("Gene_1", "Gene_2", "Gene_3","Gene_4")
geneNames <- c(1000, 3000, 10000, 12000)
expression <- c(100, 3000, 200, 1000)
geneLengths <- cbind(expression,geneLengths)
geneMatrix rownames(geneMatrix) <- geneNames
geneMatrix
## expression geneLengths
## Gene_1 1000 100
## Gene_2 3000 3000
## Gene_3 10000 200
## Gene_4 12000 1000
HINT - We calculated LNE before in vectors exercises’ bonus question
<- geneMatrix[,"expression"]/geneMatrix[,"geneLengths"]
lne <- cbind(geneMatrix,lne)
geneMatrix geneMatrix
## expression geneLengths lne
## Gene_1 1000 100 10
## Gene_2 3000 3000 1
## Gene_3 10000 200 50
## Gene_4 12000 1000 12
<- geneMatrix[geneMatrix[,"geneLengths"] > 200,]
smallGeneMatrix smallGeneMatrix
## expression geneLengths lne
## Gene_2 3000 3000 1
## Gene_4 12000 1000 12
<- geneMatrix[geneMatrix[,"geneLengths"] > 200 & geneMatrix[,"expression"] > 300,c("expression","lne")]
smallGeneMatrix smallGeneMatrix
## expression lne
## Gene_2 3000 1
## Gene_4 12000 12
Bonus Question
- Calculate the sum of expression and length columns for only genes with length > 100.
<- sum(geneMatrix[geneMatrix[,"geneLengths"] > 100,"expression"])
expressionSum <- sum(geneMatrix[geneMatrix[,"geneLengths"] > 100,"geneLengths"])
geneLengthSum #OR
<- colSums(geneMatrix[geneMatrix[,"geneLengths"] > 100,c("expression","geneLengths")])
expressionAndGeneLengthSum expressionAndGeneLengthSum
## expression geneLengths
## 25000 4200