replace.cells: replace the values in a table

Description Usage Arguments Details Value Author(s) Examples

Description

replace the values in a table, at specific positions, referenced by the row name/index, the column name/index.

Usage

1
replace.cells(tab, row, col, val)

Arguments

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

Details

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.

Value

a matrix or data.frame like tab, with those values specified by the row, col tuples changed to the values specified by val.

Author(s)

Mark Cowley, 2011-09-20

Examples

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)

drmjc/mjcbase documentation built on May 15, 2019, 2:27 p.m.