PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, September 17, 2022

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

 September 17, 2022     data.table, justify, printing, r     No comments   

Issue

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)

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


Answered By - Waldi
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing