Display Only Reduced Part of Text Output in R Notebook

431 views Asked by At

When displaying output of an R Notebook, a text output will be displayed in its entirety. Is there a way to display only the first part of the text output, to get the "gist" of what is being output?

As an example, the output below shows a block of text. I realize the print() command does not know what should be displayed. However, in displaying an R Notebook, I'd like to avoid text outputs that are multiple pages long. Can the text output block be limited to a certain size.

enter image description here

1

There are 1 answers

0
xosp7tom On

I am not sure what you meant by 'gist', as summary already gives gist of the dataframe... but here are various commands to see some of dataset.

> summary(mtcars[1])
      mpg       
 Min.   :10.40  
 1st Qu.:15.43  
 Median :19.20  
 Mean   :20.09  
 3rd Qu.:22.80  
 Max.   :33.90  
> str(summary(mtcars))
 'table' chr [1:6, 1:11] "Min.   :10.40  " "1st Qu.:15.43  " ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:6] "" "" "" "" ...
  ..$ : chr [1:11] "     mpg" "     cyl" "     disp" "      hp" ...
> head(summary(mtcars),1)
      mpg             cyl             disp             hp       
 Min.   :10.40   Min.   :4.000   Min.   : 71.1   Min.   : 52.0  
      drat             wt             qsec             vs        
 Min.   :2.760   Min.   :1.513   Min.   :14.50   Min.   :0.0000  
       am              gear            carb      
 Min.   :0.0000   Min.   :3.000   Min.   :1.000  
> tail(summary(mtcars),1)
      mpg             cyl             disp             hp       
 Max.   :33.90   Max.   :8.000   Max.   :472.0   Max.   :335.0  
      drat             wt             qsec             vs        
 Max.   :4.930   Max.   :5.424   Max.   :22.90   Max.   :1.0000  
       am              gear            carb      
 Max.   :1.0000   Max.   :5.000   Max.   :8.000  
> summary(mtcars)[,1]

"Min.   :10.40  " "1st Qu.:15.43  " "Median :19.20  " "Mean   :20.09  " 

"3rd Qu.:22.80  " "Max.   :33.90  " 

> summary(mtcars)[1,]
               mpg                cyl               disp                 hp 
 "Min.   :10.40  "  "Min.   :4.000  "  "Min.   : 71.1  "  "Min.   : 52.0  " 
              drat                 wt               qsec                 vs 
 "Min.   :2.760  "  "Min.   :1.513  "  "Min.   :14.50  " "Min.   :0.0000  " 
                am               gear               carb 
"Min.   :0.0000  "  "Min.   :3.000  "  "Min.   :1.000  "