[R] round() a data frame containing 'character' variables?

Martin Maechler maechler at stat.math.ethz.ch
Thu Aug 11 16:34:14 CEST 2011


>>>>> Liviu Andronic <landronimirc at gmail.com>
>>>>>     on Wed, 10 Aug 2011 11:46:55 +0200 writes:

    > Hello On Wed, Aug 10, 2011 at 11:41 AM, Dimitris
    > Rizopoulos <d.rizopoulos at erasmusmc.nl> wrote:
    >> One approach is the following:
    >> 
    >> numVars <- sapply(iris, is.numeric) iris[numVars] <-
    >> lapply(iris[numVars], round, digits = 2) head(iris)
    >> 
    > That's interesting, but still doesn't do what I
    > need. Since it's a read-only View() operation I would like
    > to avoid at all cost modifying the original data
    > frame. And since my data frames are relatively big, I
    > would like to avoid generating unnecessary
    > copies. Basically I would need round() to ignore objects
    > that it knows it cannot handle.

    > Any other ideas?

Well, as you say it's  "View()" only, so why don't you just
"view" the result of

something like
	  print(<data>, digits = 2)

(it does correspond to  signif(), rather than round(),
 but I think that that's more sensible anyway).

Martin



More information about the R-help mailing list