Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is R producing an extra space at the start of this expression's result?

Tags:

r

Why does R produce an extra space at the start of the first expression's result, but there is no such extra space at the start of the second expression's result? I am using R 2.13.1.

> 20:30
 [1] 20 21 22 23 24 25 26 27 28 29 30
> 20:24
[1] 20 21 22 23 24
like image 300
stackoverflowuser2010 Avatar asked Jan 17 '14 04:01

stackoverflowuser2010


People also ask

How do I get rid of extra spaces in R?

gsub() function is used to remove the space by removing the space in the given string.

How do you handle space in regex?

Find Whitespace Using Regular Expressions in Java The most common regex character to find whitespaces are \s and \s+ . The difference between these regex characters is that \s represents a single whitespace character while \s+ represents multiple whitespaces in a string.

How do you remove whitespace from the beginning and end of a string?

String result = str. trim(); The trim() method will remove both leading and trailing whitespace from a string and return the result.

How do you remove spaces at the beginning of a string in Python?

Use the . strip() method to remove whitespace and characters from the beginning and the end of a string. Use the . lstrip() method to remove whitespace and characters only from the beginning of a string.


1 Answers

Given the encouraging comments, reposted as an answer.

OMG R is a total FAIL! Run away! :-)

Seriously, try 1:50 amd then 1:1000 . It appears to be deliberate, to get the [1] tag on the first line of output to be right-justified with the [24] (or whatever value is the wrap on your console) tag on the second line of output. Josh O'Brien went further and observed a double-indent when indices went up to 3 digits.

like image 168
Carl Witthoft Avatar answered Sep 29 '22 08:09

Carl Witthoft