Let’s have a dataframe with long strings in one column:
df<-data.frame(short=rnorm(10,0,1),long=replicate(10,paste(rep(sample(letters),runif(1,5,8)),collapse="")))
How could I print the dataframe without showing the entire string?
Something like this:
short long
1 0.2492880 ghtaprfv...
2 1.0168434 zrbjxvci...
3 0.2460422 yaghkdul...
4 0.1741522 zuabgxpt...
5 -1.1344230 mzhjtwcr...
6 -0.7104683 fcbhuegt...
7 0.2749227 aqyezhbl...
8 -0.4395554 azecsbnk...
9 2.2837716 lkgwzedf...
10 0.7695538 omiewuyn...
You can redefine the
print.data.framemethod, and in this function usesubstrto trim your character vectors to the desired maximum length:Create data. Note my addition of
stringsAsFactors=FALSE:Print
data.frame: