Last active
April 19, 2020 15:02
-
-
Save danielecook/342d0097cfa7e08573e3f107f13cff09 to your computer and use it in GitHub Desktop.
R row iterator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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