Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I instruct R to left justify the text in a character column when displaying a data.table?

How can I instruct R to left justify the text in a character column when displaying a data.table?

For example, how might I instruct R to left justify column "text" in the following output so that it matches the desired output?

library(data.table)
(data1 <- data.table(text = c("AAAAAA", "B", "C"), number = c(1, 2, 3)))
#>      text number
#> 1: AAAAAA      1
#> 2:      B      2
#> 3:      C      3

Created on 2022-02-10 by the reprex package (v2.0.1)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Desired output:

#>    text   number
#> 1: AAAAAA      1
#> 2: B           2
#> 3: C           3

>Solution :

You could pass justify = "left" argument to print.data.table:

print(data1,justify="left")
     text number
   <char>  <num>
1: AAAAAA      1
2: B           2
3: C           3
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading