Skip to contents

Function addRowWithName()

This function does no more than adding a row to a data frame with rbind and giving it a name:

x <- data.frame(value = 10:11)

new_row <- data.frame(value = sum(x$value))

kwb.utils::addRowWithName(x, new_row, row.name = "total")
#>       value
#> 1        10
#> 2        11
#> total    21

Function addSuffixToColumns()

This function adds a postfix to the column names of a data frame. This may be useful when column-binding data frames. The function can be used to indicate the origin of each column by giving it a suffix related to the data frame that it originates from.

# Define a first data frame
data_frame_1 <- data.frame(
  id = 1:2, 
  first = c("Peter", "Mary"), 
  last = c("Miller", "Smith")
)

# Define a second data frame
data_frame_2 <- data.frame(
  height_cm = c(181, 171),
  weigth_kg = c(68, 59)
)

# Column-bind the data frames, after giving their columns a unique suffix
cbind(
  kwb.utils::addSuffixToColumns(data_frame_1, "_1"),
  kwb.utils::addSuffixToColumns(data_frame_2, "_2")
)
#>   id_1 first_1 last_1 height_cm_2 weigth_kg_2
#> 1    1   Peter Miller         181          68
#> 2    2    Mary  Smith         171          59

Function asNoFactorDataFrame

This function is a shortcut to as.data.frame(..., stringsAsFactors = FALSE). Using this function may slightly improve the readability of a script (as the number of arguments passed to the function is reduced):

m <- matrix(letters[1:6], nrow = 2)

result_1 <- kwb.utils::asNoFactorDataFrame(m)
result_2 <- as.data.frame(m, stringsAsFactors = FALSE)

identical(result_1, result_2)
#> [1] TRUE

Functions Working on Data Frames

Function columnToDate()

Function columnwisePercentage()

Function dropUnusedFactorLevels()

Function extractRowRanges()

Function fullySorted()

Function firstPosixColumn()

Function getKeywordPositions()

Function hsAddMissingCols()

Function hsDelEmptyCols()

Function hsRenameColumns()

Function insertColumns()

Function mergeAll()

Function moveColumnsToFront()

Function noFactorDataFrame()

Function pasteColumns()

Function pasteColumns0()

Function posixColumnAtPosition()

Function rbindAll()

Function removeColumns()

Function removeEmptyColumns()

Function renameAndSelect()

Function renameColumns()

Function resetRowNames()

Function roundColumns()

Function rowwisePercentage()

Function safeColumnBind()

Function safeMerge()

Function safeRowBind()

Function safeRowBindAll()

Function selectColumns()

Function setColumns()

Function splitIntoFixSizedBlocks()

Function tableLookup()

Function unmerge()