[R] Wrap column headers caption

Erik Iverson eriki at ccbr.umn.edu
Tue Jul 13 19:54:13 CEST 2010


> Using this dataframe with quite long column headers, how can I wrap the 
> text so that the columns are narrower. I was trying to use strwrap without 
> success. Thanks
> 
> reportDF <- structure(list(IDDate = c("3/12/2010", "3/13/2010", "3/14/2010",
> "3/15/2010"), FirstRunoftheYear = c("33 (119 ? 119)", "n (0 ? 0)", "893 (110 ? 
> 146)",
> "140 (111 ? 150)"), SecondRunoftheYear = c("33 (71 ? 71)", "n (0 ? 0)",
> "337 (67 ? 74)", "140 (68 ? 84)"), ThirdRunoftheYear = c("890 (32 ? 47)",
> "n (0 ? 0)", "10,602 (32 ? 52)", "2,635 (34 ? 66)"), FourthRunoftheYear = c("0 ( 
> ? )",
> "n (0 ? 0)", "0 ( ? )", "0 ( ? )"), LastRunoftheYear = c("0 ( ? )", "n (0 ? 0)",
> "0 ( ? )", "0 ( ? )")), .Names = c("IDDate", "First Run of the Year", "Second 
> Run of the Year",
> "Third Run of the Year", "Fourth Run of the Year", "Last Run of the Year"), 
> row.names = c(NA, 4L), class = "data.frame")

I could be wrong here, but I don't think there's a way to do that as 
print.data.frame is currently defined.  You might find the print.gap 
argument of some use, it ultimately gets passed down to print.default 
and will affect the output.

I can't think of a way to do this, hopefully someone else will have an 
idea.



More information about the R-help mailing list