[R] stop R from rounding

Martin Maechler maechler at stat.math.ethz.ch
Fri Oct 21 08:51:56 CEST 2011


>>>>> David Winsemius <dwinsemius at comcast.net>
>>>>>     on Thu, 20 Oct 2011 01:51:28 -0400 writes:

    > On Oct 19, 2011, at 11:29 PM, Alyse wrote:

    >> Hello,
    >> 
    >> I have a column in a data frame that need to be 10 digits long.  As  
    >> such:
    >> 
    >> Decimal.Year
    >> 1  1994.25997
    >> 2  1994.26020
    >> 
    >> However, R keeps rounding the digits.  As such:
    >> 
    >> Decimal.Year
    >> 1  1994.260
    >> 2  1994.260
    >> 
    >> *Is there any way to stop this from happening?*
    >> 
    >> Here is how I created the data frame:
    >> 
    >> x <- read.table('bats_1994_CTD.txt')
    >> colnames(x) <-
    >> c 
    >> ('Cruise 
    >> ','Dec.Year','Lat.N','Long.W','Press','Depth','Temp','Sal','Oxy')
    >> date <- subset(x,select=c(Dec.Year), (Depth<201) & (Depth>199))
    >> datelist <- list(date$Dec.Year)
    >> temp <- subset(x,select=c(Temp), (Depth<201) & (Depth>199))
    >> tempmean <- aggregate(temp,by=datelist,FUN=mean)
    >> tempframe <- data.frame(tempmean) #the first column of this  
    >> dataframe is the
    >> one that I don't want R to round

    > R is not rounding. It is displaying with less than full precision. You  
    > can control that with format or sprintf or formatC.

Well, or more simply in such situations by

  options(digits = 10) # if it's  10 (significant) digits you want
                       # uses 10 (sig..) digits *FROM NOW ON*
                       
or, if it's just for this one "printing",
instead of saying
  
    x

which is *equivalent* to  print(x), use

   print(x, digits = 10)



More information about the R-help mailing list