R/spreadNet.R

Defines functions spreadNet

spreadNet <- function(df) {
  df[, 3] <- as.numeric(df[, 3])
  row_names <- unique(df[, 1])
  col_names <- unique(df[, 2])
  spread.df <-
    data.frame(matrix(0, nrow = length(row_names), ncol = length(col_names)), row.names =
                 row_names)
  colnames(spread.df) <- col_names
  for (i in 1:nrow(df)) {
    spread.df[as.character(df[i, 1]), as.character(df[i, 2])] <-
      df[i, 3]
  }
  spread.df
}

Try the SCORPION package in your browser

Any scripts or data that you put into this service are public.

SCORPION documentation built on June 22, 2024, 9:35 a.m.