[R] stop R from rounding

David Winsemius dwinsemius at comcast.net
Thu Oct 20 07:51:28 CEST 2011


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.
>
> Thank you!
>
> --
> View this message in context: http://r.789695.n4.nabble.com/stop-R-from-rounding-tp3920803p3920803.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list