-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathR_worksheet.R
43 lines (33 loc) · 1021 Bytes
/
R_worksheet.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#put on github: 1. bash examples 2. jingle bells 3. this file
#directory management
getwd()
setwd("~/SMTB_2019_Rotation/")
getwd()
#explore the standard normal distribution
distrib <- rnorm(n = 100, mean = 0, sd = 1)
length(distrib)
head(distrib)
hist(distrib)
distrib <- rnorm(n = 10000, mean = 0, sd = 1)
hist(distrib)
mean(distrib)
sd(distrib)
N <- 100
mymat <- matrix(rnorm(n = N, mean = 0, sd = 1), nrow = sqrt(N))
write.table(mymat, "~/exercise_table.txt", row.names = F, col.names = F, quote = F)
system("mv ~/exercise_table.txt ~/SMTB_2019_Rotation/")
mymat2 <- read.table("exercise_table.txt", header = F, stringsAsFactors = F, sep = " ")
head(mymat2)
dim(mymat2)
nrow(mymat2)
ncol(mymat2)
mymat2[1:3,1:3] #indexing
mymat2[6,9] #select a value
rowSums(mymat2) #sums over rows
rowSums(t(mymat2)) #sums over columns
mean(as.matrix(mymat2)) #compute average
s <- c() #sum gene expression over each gene individually
for (i in 1:nrow(mymat2)){
s[i] <- sum(mymat2[i,])
}
all(s == rowSums(mymat2))