Description Usage Arguments Details Value Author(s) Examples
replace the values in a table, at specific positions, referenced by the row name/index, the column name/index.
1 | replace.cells(tab, row, col, val)
|
tab |
a matrix or data.frame of values, to be edited |
row |
a vector of row names or indices |
col |
a vector of col names or indices |
val |
a vector of values to insert into tab at the locations specified by row and col |
Common usage scenario
Given a spreadsheet of patients with mutated genes, you want to indicate in a square matrix
of genes x patients, which ones have a mutation. Thus a priori, you know which elements
you want to edit, but it's very fiddly using the "[", "]" nomenclature to indicate which
cells within the matrix to edit.
a matrix
or data.frame
like tab, with those values specified by the
row
, col
tuples changed to the values specified by val
.
Mark Cowley, 2011-09-20
1 2 3 4 5 | mat <- matrix(0, 5, 5)
replace.cells(mat, 1:5, 1:5, rep(NA, 5))
df <- as.data.frame(mat)
dimnames(df) <- list(letters[1:5], LETTERS[1:5])
replace.cells(df, c("a", "a", "e"), c("D", "B", "A"), 1:3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.