Box Me

[This article was first published on Drunks&Lampposts » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Here’s a short R function I wrote to turn a long data set into a wide one for viewing. It’s not the most exciting function ever but I find it quite useful when my screen is wide and short. It simply cuts the data set horizontally into equal size pieces and puts them side by side. Lazy I know!

#'Turns an overly long data frame into something easier to look at
#' @param d A dataframe or matrix
#' @param nrow The number of rows you would like to see in the new dataframe
#' @examples
#' test.set<-data.frame(x=rnorm(100), y=rnorm(100))
#' boxMe(test.set, 18)
#' library(ggplot2)
#' boxMe(diamonds, 10)

boxMe<-function(d, nrow){
  # Number of rows and columns
  rem<-r %% nrow # Number of blank rows
  reps<-floor(r/nrow) # Number of folds
  s<-seq(1, reps*nrow, by=nrow) # Breaks
  box<-d[1:nrow,] # First col
  for (i in s[-1]){

    box<-cbind(box, ap)
  #Append remainder
  if (rem>0){
    null.block<, (n.null.rows*c)), nrow=n.null.rows))
    last.block<-rbind(rem.rows, null.block)
    box<-cbind(box, last.block)



To leave a comment for the author, please follow the link and comment on their blog: Drunks&Lampposts » R. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)