R basic

In this post, I will document all basic for R and R programming.

Scenario 1, useful R introduction manuals and websites

	
  • CRAN
  • Thomas Girke -- USC
  • Scenario 2, differentiating matrix and dataframe

    A matrix is a two-dimensional data structure. All the elements of a matrix must be of the same type (numeric, logical, character, complex).
    A data frame combines features of matrices and lists. In fact we can think of a data frame as a rectangular list, that is, a list in which all items have the length length. The items of the list serve as the columns of the data frame, so every item within a particular column has to be of the samne type. However, different columns can be of different types. 
    Matrix -- Dataframe
    

    Scenario 3, how to combine two matrix by rownames

    It seems easy and legitimate question, but not everyone knows it. I found one pretty decent solution

    
    cbind.fill <- function(x, y){
      xrn <- rownames(x)
      yrn <- rownames(y)
      rn <- union(xrn, yrn)
      xcn <- colnames(x)
      ycn <- colnames(y)
      if(is.null(xrn) | is.null(yrn) | is.null(xcn) | is.null(ycn)) 
        stop("NULL rownames or colnames")
      z <- matrix(NA, nrow=length(rn), ncol=length(xcn)+length(ycn))
      rownames(z) <- rn
      colnames(z) <- c(xcn, ycn)
      idx <- match(rn, xrn)
      z[!is.na(idx), 1:length(xcn)] <- x[na.omit(idx),]
      idy <- match(rn, yrn)
      z[!is.na(idy), length(xcn)+(1:length(ycn))] <- y[na.omit(idy),]
      return(z)
    }
    
    

    Scenario 4, I want to have a thorough note on apply function in R

    There was a simple question on R apply function. Although it seems quite straightforward, it causes lots of confusion for people. Therefore, I decide to write a thorough document for this.


    Scenario 5, Invoking R from the command line

    Here gives a good example to invoke R from the linux command line.

    Scenario 6, Use R to perform clustering and then produce a heatmap

    Good example-by-mannheimia
    Example of savvi by Earl Glynn
    

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    This site uses Akismet to reduce spam. Learn how your comment data is processed.