[R] print only a few lines of an object
Fox, John
j|ox @end|ng |rom mcm@@ter@c@
Wed Mar 23 20:34:30 CET 2022
Dear Naresh,
You could try the brief() function in the car package, which has methods for matrices and data frames. For example:
> X <- matrix(rnorm(20000*200), nrow = 20000)
> library("car")
Loading required package: carData
> brief(X)
20000 x 200 matrix (19995 rows and 197 columns omitted)
[,1] . . . [,199] [,200]
[1,] -0.03153991 1.29516494 -2.6333638
[2,] 0.21286783 0.01152682 -1.0662203
[3,] 0.63017820 0.68932816 1.5035356
. . .
[19999,] 2.68200662 0.24294658 -0.1350098
[20000,] 0.76880930 1.22899828 -1.3462279
> brief(X, rows = c(5, 5), cols = c(5, 5))
20000 x 200 matrix (19990 rows and 190 columns omitted)
[,1] [,2] [,3] [,4] [,5] . . .
[1,] -0.03153991 1.51280101 0.56670537 1.3421424 -0.0901379
[2,] 0.21286783 0.01565378 0.36631559 -1.6334725 -0.4110920
[3,] 0.63017820 0.64677503 0.23708531 -1.0694868 0.6824060
[4,] -0.30640844 -0.50453994 -0.02955539 -0.3602093 0.9529470
[5,] -0.14800239 -0.36379589 0.26398965 0.7045783 -0.4371091
[,196] [,197] [,198] [,199] [,200]
[1,] 2.4384271 -0.8562120 0.03272777 1.29516494 -2.6333638
[2,] 2.3218889 0.9590918 -1.02492163 0.01152682 -1.0662203
[3,] 0.5408822 1.1099126 -0.35874326 0.68932816 1.5035356
[4,] -1.2347136 0.1547285 -0.94671222 -0.87190563 -0.8089031
[5,] 0.1008432 -0.3179192 0.18579939 -0.31228407 -0.3491618
. . .
[19996,] 0.77793106 -1.69263749 -0.11233025 0.1823454 -1.3472522
[19997,] 0.50623281 1.63893912 -1.28729766 0.3620005 0.4693123
[19998,] -1.25504937 0.34050657 0.48436453 -0.1727108 0.4209498
[19999,] 2.68200662 -1.25888437 0.68085064 -0.3954497 -0.4057523
[20000,] 0.76880930 -0.48637856 1.68292021 0.8830241 0.4467292
[19996,] 1.1499971 -1.5115928 -0.97399354 1.21192716 0.4767529
[19997,] 0.5482631 -0.5797288 -0.13904089 -1.35133895 0.2814043
[19998,] -0.9352181 -1.1193794 0.37612204 1.09246093 -0.3628966
[19999,] -0.4141664 -0.5314562 0.60420993 0.24294658 -0.1350098
[20000,] -0.4208899 -1.4542644 -0.20223993 1.22899828 -1.3462279
I hope this helps,
John
-----------------------------------------------------------------
John Fox
Professor Emeritus
McMaster University
Hamilton, Ontario, Canada
Web: https://socialsciences.mcmaster.ca/jfox/
> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Naresh Gurbuxani
> Sent: Wednesday, March 23, 2022 2:44 PM
> To: r-help using r-project.org
> Subject: [R] print only a few lines of an object
>
> In an R session, when I type the name of an object, R prints the entire object
> (for example, a 20000 x 5 data.frame). Is it possible to change the default
> behavior so that only the first five and last five rows are printed?
>
> Similarly, if the object is a 20000 x 200 matrix, the default behavior will be to
> print first five and last five columns, combined with first five and last five rows.
>
> Thanks,
> Naresh
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
More information about the R-help
mailing list