[R] problems with rounding in output

Gabor Grothendieck ggrothendieck at gmail.com
Tue Apr 11 07:50:33 CEST 2006


Try:

> sprintf("(%.2f)", pi)
[1] "(3.14)"

On 4/11/06, Brian Quinif <bquinif at gmail.com> wrote:
> Perhaps someone will have a solution to my more general problem, but
> here is the specific one:
>
> I used the round() function to round some estimates to 3 decimal
> places.  I then sent put the rounded estimates in a matrix and used
> latex() to make a LaTeX table from them.  However, in my table, there
> are estimtes which only have 2 decimal places. I assume that the third
> decimal place in these numbers was equal to zero, so the round()
> function simply cut off the superfluous zero.  However, I want all of
> my estimates to have the same number of digits.  Is there a way to
> force R to keep all three digits, even if the last one is zero?
>
> Now, getting to the more general issue, to which a solution might
> negate the need for a solution to the first part of this email.  I
> want to create a table in which all of the standard errors are in
> parentheses.  The solution I used was to input the std. errors into
> the matrix to be used for making the table as follows
>
> paste('(',satt.yr.hrs$se,')',sep='')
>
> However, after doing so, my LaTeX output had all of the digits that R
> output without rounding like it normally does.  So, I tried using the
> round() command as described above.  Another problem with my solution
> is that the negative signs in my LaTeX tables come out as hyphens, not
> the usual negative signs from math mode.
>
> Does anyone have a better solution for how to put my std. errors in parentheses?
>
> Thanks,
>
> BQ
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list