R super-fast intro

Variables and value assignment:

In [1]:
a <- 1
In [2]:
a
1
In [3]:
a=13
In [4]:
a
13

R is a good tool to work with vectors

In [5]:
v1 <- c(1,3,5,6,8)
In [6]:
v1
  1. 1
  2. 3
  3. 5
  4. 6
  5. 8
In [7]:
v2 <- 4:8
In [8]:
v2
  1. 4
  2. 5
  3. 6
  4. 7
  5. 8
In [9]:
v3 <- rep(0,5)
In [10]:
v3
  1. 0
  2. 0
  3. 0
  4. 0
  5. 0

On vectors you can do various operations

In [11]:
v2 + 1
  1. 5
  2. 6
  3. 7
  4. 8
  5. 9
In [12]:
v2 * 3
  1. 12
  2. 15
  3. 18
  4. 21
  5. 24

Vectors can be combined into matrices

In [13]:
m1 <- cbind(v1,v2,v3)
In [14]:
m1
v1v2v3
140
350
560
670
880
In [15]:
m2 <- rbind(v1,v2,v3)
In [16]:
m2
v113568
v245678
v300000

Matrices operations, eg. multiplication

In [17]:
m2 %*% m1
v1v2v3
v11351550
v21551900
v3 0 00

Matrices indexing to get rows and columns

In [18]:
m1[c(1,3,4),]
v1v2v3
140
560
670
In [19]:
m1[1:4, 1:2]
v1v2
14
35
56
67

How big is the matrix? Dimensions...

In [20]:
dim(m1)
  1. 5
  2. 3

More complex objects - lists

In [21]:
l1 <- list()
In [22]:
l1[[1]] <- m1
In [23]:
l1
  1. v1v2v3
    140
    350
    560
    670
    880
In [24]:
l1[[2]] <- v2
In [25]:
l1
  1. v1v2v3
    140
    350
    560
    670
    880
    1. 4
    2. 5
    3. 6
    4. 7
    5. 8
In [26]:
l1$description <- "turlututu"
In [27]:
l1
[[1]]
     v1 v2 v3
[1,]  1  4  0
[2,]  3  5  0
[3,]  5  6  0
[4,]  6  7  0
[5,]  8  8  0

[[2]]
[1] 4 5 6 7 8

$description
[1] "turlututu"

More complex objects

In [28]:
load("DEGlist.Rd")
In [29]:
class(y)
'DGEList'
In [30]:
str(y)
Loading required package: edgeR
Loading required package: limma
Warning message:
“package ‘limma’ was built under R version 3.4.2”
Formal class 'DGEList' [package "edgeR"] with 1 slot
  ..@ .Data:List of 11
  .. ..$ : int [1:57992, 1:12] 11 2089 0 2 0 0 0 0 45 0 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : chr [1:57992] "ENSG00000223972" "ENSG00000227232" "ENSG00000278267" "ENSG00000243485" ...
  .. .. .. ..$ : chr [1:12] "mfc_cnt_1" "mfc_cnt_2" "mfc_cnt_3" "mfc_dac_1" ...
  .. ..$ :'data.frame':	12 obs. of  3 variables:
  .. .. ..$ group       : Factor w/ 1 level "1": 1 1 1 1 1 1 1 1 1 1 ...
  .. .. ..$ lib.size    : num [1:12] 22230293 30709932 88453516 41361601 44072270 ...
  .. .. ..$ norm.factors: num [1:12] 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ : num [1:12, 1:3] 1 1 1 0 0 0 0 0 0 0 ...
  .. .. ..- attr(*, "dimnames")=List of 2
  .. .. .. ..$ : chr [1:12] "1" "2" "3" "4" ...
  .. .. .. ..$ : chr [1:3] "mfc.cnt" "mfc.dac" "yb5.cnt"
  .. .. ..- attr(*, "assign")= int [1:3] 1 1 1
  .. .. ..- attr(*, "contrasts")=List of 1
  .. .. .. ..$ Treat: chr "contr.treatment"
  .. ..$ : num 0.145
  .. ..$ : num [1:57992] 0.2418 0.0464 0.3323 0.2976 0.3323 ...
  .. ..$ : num [1:57992] 0.3984 0.0757 0.3323 0.2089 0.3323 ...
  .. ..$ : num [1:57992] 0.842 6.422 -4.641 -1.735 -4.423 ...
  .. ..$ : chr "locfit"
  .. ..$ : num 3.2
  .. ..$ : num 0.356
  .. ..$ : num 0.278
In [33]:
y@.Data[[1]][1:10, 1:10]
mfc_cnt_1mfc_cnt_2mfc_cnt_3mfc_dac_1mfc_dac_2mfc_dac_3yb5_cnt_1yb5_cnt_2yb5_cnt_3yb5_dac_1
ENSG00000223972 11 18 55 46 57 56 59 35 32 278
ENSG000002272322089244175593644417243294055256825686803
ENSG00000278267 0 0 0 0 0 0 0 0 0 0
ENSG00000243485 2 3 8 8 11 13 12 7 9 33
ENSG00000237613 0 0 0 0 0 0 1 0 0 2
ENSG00000268020 0 0 0 0 0 0 0 0 1 0
ENSG00000240361 0 0 0 0 0 0 0 0 0 0
ENSG00000186092 0 0 0 0 0 0 0 0 0 0
ENSG00000238009 45 80 183 110 111 122 106 73 71 150
ENSG00000239945 0 0 0 0 0 0 0 0 0 0
In [34]:
attributes(y)
$names
  1. 'counts'
  2. 'samples'
  3. 'design'
  4. 'common.dispersion'
  5. 'trended.dispersion'
  6. 'tagwise.dispersion'
  7. 'AveLogCPM'
  8. 'trend.method'
  9. 'prior.df'
  10. 'prior.n'
  11. 'span'
$class
'DGEList'
In [35]:
y$samples
grouplib.sizenorm.factors
mfc_cnt_11 222302931
mfc_cnt_21 307099321
mfc_cnt_31 884535161
mfc_dac_11 413616011
mfc_dac_21 440722701
mfc_dac_31 504416901
yb5_cnt_11 717722771
yb5_cnt_21 498742371
yb5_cnt_31 453365751
yb5_dac_11 569362041
yb5_dac_21 476693981
yb5_dac_31 499079861
In [ ]: