Skip to content

Instantly share code, notes, and snippets.

@maurolepore
Last active September 21, 2017 20:54
Show Gist options
  • Save maurolepore/8d8caf82cf56e94349e6406b42356c83 to your computer and use it in GitHub Desktop.
Save maurolepore/8d8caf82cf56e94349e6406b42356c83 to your computer and use it in GitHub Desktop.

Adapted from code by Shameema Jafferjee Esufali

add_subquadrat <- function(df) {
  x1 <- c(0, 10, 10, 0)
  x2 <- c(10, 20, 20, 10)
  y1 <- c(0, 0, 10, 10)
  y2 <- c(10, 10, 20, 20)

  df_list <- replicate(4, data.frame(NULL, stringsAsFactors = FALSE))

  for (n in 1:4) {
    condition <- df$lx >= x1[n] & df$lx < x2[n] & df$ly >= y1[n] & df$ly < y2[n]
    df_list[[n]] <- df[condition, ]
    df_list[[n]]$subquadrat <- n
  }
  df_list
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment