add_row_to_ternary_df: Add a row to a 3-valued (ternary) 'data.frame'

View source: R/operations.R

add_row_to_ternary_dfR Documentation

Add a row to a 3-valued (ternary) data.frame

Description

Use this function on a data.frame object (with values only in the 3-element set {-1,0,1} ideally - specifying either a positive, negative or none/absent condition/state/result about something) and add an extra first or last row vector with zero values, where 1 and -1 will be filled when the column names of the given data.frame match the values in the values.pos or values.neg vector parameters respectively.

Usage

add_row_to_ternary_df(
  df,
  values.pos,
  values.neg,
  pos = "first",
  row.name = NULL
)

Arguments

df

a data.frame object with values only in the the 3-element set {-1,0,1}. The column names should be node names (gene, protein names, etc.).

values.pos

a character vector whose elements are indicators of a positive state/condition and will be assigned a value of 1. These elements must be a subset of the column names of the given df parameter. If empty, no values equal to 1 will be added to the new row.

values.neg

a character vector whose elements are indicators of a negative state/condition and will be assigned a value of -1. If empty, no values equal to -1 will be added to the new row. These elements must be a subset of the column names of the given df parameter.

pos

string. The position where we should put the new row that will be generated. Two possible values: "first" (default) or "last".

row.name

string. The name of the new row that we will added. Default value: NULL.

Value

the df with one extra row, having elements from the {-1,0,1} set depending on values of values.pos and values.neg vectors.

Examples

df = data.frame(c(0,-1,0), c(0,1,-1), c(1,0,0))
colnames(df) = c("A","B","C")
df.new = add_row_to_ternary_df(df, values.pos = c("A"), values.neg = c("C"), row.name = "Hello!")


usefun documentation built on Sept. 17, 2023, 9:06 a.m.