R/aveProbe.R

"aveProbe" <-
function(x, imat=NULL, ids){
  if (!setequal(rownames(x), names(ids))) cat("Warnings: The names of identifiers should be matched up with the names of probes in the data", "\n")
  if (is.list(ids)) cat("Warnings: The variable ids should be converted to a vector", "\n")
  uu <- unique(ids)
  uu <- uu[!is.na(uu)]
  if (is.null(imat)) {
    newx <- matrix(0, nrow = length(uu), ncol = ncol(x))
    rownames(newx) <- uu
    colnames(newx) <- colnames(x)
    for (i in 1:length(uu)) {
      ind <- which(uu[i] == ids)
      if (length(ind) == 1)
        newx[i, ] <- as.numeric(x[ind, ])
      else newx[i, ] <- apply(x[ind, ], 2, median)}
    list(newx = newx)}
  else {
    newx <- matrix(0, nrow = length(uu), ncol = ncol(x))
    newimat <- matrix(0, nrow = length(uu), ncol = ncol(imat))
    rownames(newx) <- rownames(newimat) <- uu
    colnames(newx) <- colnames(x)
    colnames(newimat) <- colnames(imat)
    for (i in 1:length(uu)) {
      ind <- which(uu[i] == ids)
      if (length(ind) == 1) newx[i, ] <- as.numeric(x[ind, ]) else newx[i, ] <- apply(x[ind, ], 2, median)
      if (length(ind) == 1) newimat[i, ] <- as.numeric(imat[ind, ]) else newimat[i, ] <- apply(imat[ind, ], 2, median)}
    list(newx = newx, newimat = newimat)}
}

Try the pcot2 package in your browser

Any scripts or data that you put into this service are public.

pcot2 documentation built on Nov. 8, 2020, 5:08 p.m.