David ... thank you.

OK ... so it appears there's no direct way to do this.  But I could write a 
function for printing data frames that would utilize your suggested approach, 
data.frame(lapply()).  This way, I could simply call the function with the data 
frame object as the argument.


Thanks again for the idea.
Mauricio



________________________________
 From: David Winsemius <dwinsem...@comcast.net>

Cc: "r-help@r-project.org" <r-help@r-project.org> 
Sent: Saturday, December 15, 2012 11:48 AM
Subject: Re: [R] How to limit string size when displaying data frames?


On Dec 15, 2012, at 8:27 AM, Mauricio Cornejo wrote:

> Hello,
> 
> Is there a way to set the maximum width of character columns when printing a 
> data frame?
> 
> I've looked into print(), format(), and options() and have been unsuccessful.
> 
> For example, I'd like to achieve the results below without having to modify 
> the data itself.

> data.frame(lapply(x, substr, 1, 10))
          c1         c2
1 0.13891058 ABCDEFGHIJ
2 -0.0533631 ABCDEFGHIJ
3 -0.9799945 ABCDEFGHIJ
4 0.44754950 ABCDEFGHIJ
5 0.90906556 ABCDEFGHIJ


> 
>> x <- data.frame(c1=rnorm(5), c2="ABCDEFGHIJKLMNOPQRSTUVWXYZ")
>> x
> c1                         c2
> 1  0.7076495 ABCDEFGHIJKLMNOPQRSTUVWXYZ
> 2 -0.1572245 ABCDEFGHIJKLMNOPQRSTUVWXYZ
> 3  0.3515308 ABCDEFGHIJKLMNOPQRSTUVWXYZ
> 4  0.3492925 ABCDEFGHIJKLMNOPQRSTUVWXYZ
> 5 -0.3805869 ABCDEFGHIJKLMNOPQRSTUVWXYZ
> 
>> x$c2 <- substr(x$c2, 1, 10) #Only show first 10 chars.
>> x
> c1         c2
> 1  0.7076495 ABCDEFGHIJ
> 2 -0.1572245 ABCDEFGHIJ
> 3  0.3515308 ABCDEFGHIJ
> 4  0.3492925 ABCDEFGHIJ
> 5 -0.3805869 ABCDEFGHIJ
> Thanks,
> Mauricio
>     [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to