well_df_to_mat: Convert a data.frame to a Matrix in Plate Format

View source: R/plate.R

well_df_to_matR Documentation

Convert a data.frame to a Matrix in Plate Format

Description

Extracts row and column information from the column specified by well_col (defaults to 'well') and uses this to create a matrix that contains values from the values_from column.

Usage

well_df_to_mat(df, values_from, well_col = "well", plate = NULL)

Arguments

df

A dataframe containing at least a column called "well" that contains well IDs.

values_from

Column that contains values to populate matrix.

well_col

Column containing the well IDs to extract row and column information from.

plate

Size of the plate, to override the auto-detected plate size.

Value

A matrix containing the values that were present in the data frame in the values_from column

Examples

library(wellr)

# pivot a long data frame into a matrix based on the row and col columns,
# with values from a given column
plate <- well_plate(8, 12)
plate$value <- seq(nrow(plate))
well_df_to_mat(plate, values_from = "value")

# the function also handles missing values from a plate, filling with with NA
# if certain wells are missing
plate <- well_plate(7, 11)
plate$value <- seq(nrow(plate))
well_df_to_mat(plate, values_from = "value", plate = 384)

rforbiochemists/wellr documentation built on March 28, 2024, 4:26 a.m.