R/oneRowPerId.R

Defines functions oneRowPerId

Documented in oneRowPerId

oneRowPerId = function(x, ids) {
  stopifnot(all(x[,1] %in% ids))
  x = x[ apply(x[,-1,drop=FALSE], 1, function(y) any(y!="")), ]
  d = lapply(2:ncol(x), function(i) {
    r  = character(length(ids))
    v  = sapply(split(x[,i], x[,1]), unique)
    v  = sapply(v, paste, collapse=", ")
   # mt = match(names(v), ids)
   # r[mt] = v
    mt = match(ids, names(v))
    r[!is.na(mt)] = v[mt[!is.na(mt)]]
    r[r==""] = NA
    return(I(r))
  })
  names(d) = colnames(x)[2:ncol(x)]
  do.call(data.frame, d)
}

Try the cellHTS2 package in your browser

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

cellHTS2 documentation built on Nov. 8, 2020, 6 p.m.