This project is maintained by sarbal
First things first! Download these files into your working directory:
To check your working directory:
getwd()
To set your working diretory:
setwd("H:/URP")
Run this to install/load libraries (this might take a while if you do not have most of the packages installed, so run this as soon as possible).
source("helper.R")
Object: variable, function, data etc. What fills up your environment
print("Hello World")
load("lesson1.Rdata")
sum(x)
plot(x,y)
require(limma)
source("helper.R")
Try it!
1 + 2
2/4
(4+5^7)/56
3 %% 5
log10(100)
x <- 1
y = 2
very_important_variable <- 0
not_very_important = 100
data <- 0
data <- 3
data <- x + y
data <- sqrt(x)
data <- rnorm(1000)
more_data <- 1000
data <- data + more_data
1
1.32545
5e9
'A'
'z'
"Yaaaas"
"Booo"
"Whatever"
c(1,3,5)
c('A', 'B', 'C')
c("Hello", "Goodbye")
1:100
rnorm(100)
rep(1,10)
seq(0,200,10)
my_seq <- seq(0,200,10)
my_seq[1]
my_seq[1] <- 1000
my_seq[3:6] <- c(30,20,40,36)
NOTE: in R, we count from 1 (not 0!)
diag(10)
matrix(1:10, ncol=5, nrow=2)
cbind(1:10, 10:1)
rbind(1:10, 10:1)
A <- diag(5)
A[1,5] <- 9
A
my_seq <- seq(0,200,10)
my_seq[-10]
my_seq[-10:-20]
sex <- c("male", "female", "male", "male", "female")
sex <- factor( sex, levels=c("male", "female"))
sex
sex[1] <- "female"
sex[2] <- "unknown" # This will cause an error!
B <- 1:10
C <- sex
D <- list(A,B,C)
D[[1]]
names(D) <- c("A", "B", "C")
D$A
D[["A"]]
D[[4]] <- D
D[[4]][[4]] <- D
D[[4]][[4]][[3]]
D[[1]] <- NULL
my_list = list("a", "b", "c")
your_list = list("x", "y","z")
append(my_list, your_list)
E <- list()
data.frame( x=1:10, y = rep("hello", 10) )
?order
order
Some useful functions:
length(my_list) # returns the length of an object
sort(my_seq) # sorts a list, vector or matrix
ls() # lists all the objects in your environment
{ r } `and ends before a line with `
`.Solutions: Next week!
Back to the homepage