Very often when I print a data frame (particularly when sink()-ing to a file I do NOT want the row labels (which are in such cases usually 1, 2, ... nrow(x), where x is the data frame in question). I can of course edit these out ``by hand'', but that's a bit of a pain in the pohutukawa. I recently discovered (reading the help on print.data.frame meticulously, and following it through to print.matrix) that I CAN suppress these row names by executing, e.g. > print(x,rowlab=rep("",nrow(x))) However it would be ever-so-slightly nicer (require somewhat fewer key strokes) if there were an option to print.data.frame that would allow suppression of row names. E.g. an argument ``srn=FALSE''. (Where ``srn'' stands for ``suppress row names''.) I have written my own simple minded implementation of this option, given below in case anyone else out there may have shared my frustration at being unable to figure out how to suppress row names. I would ask that the R developers consider including an argument like unto this in a future release. On a related note: I would also like, generally speaking, NOT to have row names included in LaTeX tables that I create from data frames or matrices. As far as I can discern, none of the currently available LaTeX-ing functions provide the option of suppressing the row names. The functions I've looked at are: o xtable{xtable} o latex.table{quantreg} o latex{Hmisc} It would be nice (said he wistfully) if the developers of at least one of these packages would consider adding such an option. cheers, Rolf Turner ===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+==Code for my mild revision of print.data.frame: ===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+==print.data.frame <- function (x, ..., digits = NULL, quote = FALSE, right = TRUE, srn=FALSE) { if (length(x) == 0) { cat("NULL data frame with", length(row.names(x)), "rows\n") } else if (length(row.names(x)) == 0) { print.default(names(x), quote = FALSE) cat("<0 rows> (or 0-length row.names)\n") } else { if (!is.null(digits)) { op <- options(digits = digits) on.exit(options(op)) } rowlab <- if(srn) rep("",nrow(x)) else row.names(x) print.matrix(format(x), rowlab=rowlab, ..., quote = quote, right = right) } invisible(x) } ===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===+===
>>>>> "Rolf" == Rolf Turner <rolf@math.unb.ca> >>>>> on Thu, 6 Mar 2003 15:42:51 -0400 (AST) writes:I think this definitely belongs to the R-devel mailing list -- to which I'm diverting it now. Rolf> Very often when I print a data frame (particularly when sink()-ing to Rolf> a file I do NOT want the row labels (which are in such cases usually Rolf> 1, 2, ... nrow(x), where x is the data frame in question). I can of Rolf> course edit these out ``by hand'', but that's a bit of a pain in the Rolf> pohutukawa. Rolf> I recently discovered (reading the help on print.data.frame Rolf> meticulously, and following it through to print.matrix) that Rolf> I CAN suppress these row names by executing, e.g. >> print(x,rowlab=rep("",nrow(x))) Rolf> However it would be ever-so-slightly nicer (require somewhat fewer Rolf> key strokes) if there were an option to print.data.frame that would Rolf> allow suppression of row names. E.g. an argument ``srn=FALSE''. Rolf> (Where ``srn'' stands for ``suppress row names''.) Alternatively, I'd prefer allowing rowlab = "" which looks nice enough and doesn't need a new argument BTW: You've helped uncovering a problem in R-devel: There, `rowlab' and `collab' are currently silently not working : print.matrix() doesn't have them anymore, only prmatrix() does {which is not the same any more} -- hmm... Rolf> I have written my own simple minded implementation of this option, Rolf> given below in case anyone else out there may have shared my Rolf> frustration at being unable to figure out how to suppress row names. The drawback of such an approach is that you need explicit print(.) calls (which may look a bit ugly). An alternative approach is to use default printing for a new object made from the original one --- though I must admit I'm not 100% convinced it's appropriate for your original proposal: Relatedly (but not identically aimed), I have had an alternative implemented from an S-news "discussion" including Bill Venables of about 1993. The way it's here, it's not working for data frames (just for matrices, but also other arrays), also since data frames must have unique row names by definition. But you get the main idea : empty.dimnames <- function(a) { ## 'Remove' all dimension names from an array for compact printing. d <- list(); l <- 0 for(i in dim(a)) d[[l <- l + 1]] <- rep("", i) dimnames(a) <- d a } with help : ------------------------------------------------------------------------- empty.dimnames package:sfsmisc R Documentation Empty Dimnames of an Array. Description: `Remove' all dimension names from an array for compact printing. Usage: empty.dimnames(a) Arguments: a: an `array', especially a matrix. Value: Returns `a' with its dimnames replaced by empty character strings. Author(s): Bill Venables / Martin Maechler, Sept 1993. See Also: `unname' removes the dimnames. Examples: empty.dimnames(diag(5)) # looks much nicer (a <- matrix(-9:10, 4,5)) empty.dimnames(a) # nicer, right? -------------------------------------------------------------------------