Created
July 27, 2017 20:31
-
-
Save bhive01/643d32bc13d3a55f9ac371ab3c832c96 to your computer and use it in GitHub Desktop.
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
torso <- function(d, n=5L, ...) { | |
stopifnot(length(n) == 1L) | |
center <- as.integer(nrow(d)/2) | |
left <- as.integer(center-n/3) | |
right <- as.integer(center + n/3) | |
d[seq.int(from= left, to = right, by = 1L),] | |
} | |
topntail <- function(d, n=4L) { | |
rbind(head(d,n), tail(d,n)) | |
} | |
vet <- function(d, n=4L) { | |
rbind(head(d,n), torso(d,n), tail(d,n)) | |
} | |
torso(iris) | |
topntail(iris) | |
vet(iris) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice idea. This might work a little better for the
torso
function:Using
seq_len
negates the need for calculatingright
, and ensures you'll always get the right number of rows (notice howtorso(iris,5)
currently give 4 rows instead of the 5 requested). Alson/2
seems more appropriate for calculatingleft
thann/3
. Was there a reason for the3
there?In fact, depending on your taste, it might be worth simplifying a little more by skipping the
center
assignment too: