R/split_direction.R

Defines functions split_direction

Documented in split_direction

#' Split a large table in one direction if there are blank columns or rows
#'
#' @param df Actigraphy Raw data
#' @return The lengths and values of runs of equal values in a vector.
#' @export


split_direction <- function(df,direction = "col"){
  if(direction == "col"){
    col_has_data <- unname(map_lgl(df,~!all(is.na(.x)))) ## map_lgl() returns a logical vector
    df_mapping <- make_df_index(col_has_data) ##Count the number of logical vector
    out <- map(df_mapping,~df[,.x]) ##Output data as a large list
  } else if(direction == "row"){
    row_has_data <- df %>%
      mutate_all(~!is.na(.x)) %>%
      as.matrix() %>%
      apply(1,any)
    df_mapping <- make_df_index(row_has_data)
    out <- map(df_mapping,~df[.x,])
  }
  return(out)
}
jiqiaingwu/ActigraphyUtah documentation built on April 25, 2021, 9:22 p.m.