Introduction to Biological Data Analysis


TP 2: Data structures in R

Prof. Patrick Meyer

BioSys Lab - Université de Liège

Matrices

  1. y <- matrix(45:64, nr=5, byrow=TRUE)

    Watch explanation:

  2. Matrix of 5 columns, removing third column, then matrix 4X4 of ones
    m <-rbind(matrix(c(10:19,50:59),nc=5,byrow=T),matrix(90:99,nr=2,byrow=T))
    m <- m[,-3]
    m <- matrix(1,nc=4,nr=4)
    

    Watch explanation:

Functions on vectors and matrices

  1. minmax <- function(vec) {
     c(min(vec),max(vec))
    }
    

    Watch explanation:

  2. sqrtndec <- function(vec,n){
      sqrt(sort(vec,decreasing=T)[1:n])
    }
    

    Watch explanation:

  3. valuechar <- function(vec,n){
      paste("the element number ",n, " of the vector is ",vec[n],sep="")
    }
    

    Watch explanation:

  4. is.sym <- function(mat){
      sum(!(mat==t(mat)))==0
    }
    

    Watch explanation:

  5. sqrt(apply(mat,2,sum))

    Watch explanation:

  6. sum(log(apply(mat,1,prod),2))
    

    Watch explanation:

Factors

  1. What happens when we type...

    Watch explanation:


List

  1. What happens when we type...

    Watch explanation:

  2. count.numeric <- function(liste){
      sum(sapply(liste,is.numeric))
    }
    

    Watch explanation: