Skip to content

Instantly share code, notes, and snippets.

@danielecook
Last active April 19, 2020 15:02
Show Gist options
  • Save danielecook/342d0097cfa7e08573e3f107f13cff09 to your computer and use it in GitHub Desktop.
Save danielecook/342d0097cfa7e08573e3f107f13cff09 to your computer and use it in GitHub Desktop.
R row iterator
rows <- function(tab, idx=TRUE) {
# Set idx to attach an index column
if (is.na(tab) || is.null(tab) || nrow(tab) == 0) {
return(list())
}
lapply(seq_len(nrow(tab)),
function(i) {
row <- unclass(tab[i,,drop=F])
if (idx) {
row$idx <- i
}
row
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment