[R] round() a data frame containing 'character' variables?
David Winsemius
dwinsemius at comcast.net
Thu Aug 11 16:58:23 CEST 2011
On Aug 10, 2011, at 5:46 AM, Liviu Andronic wrote:
> 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.
Then drop the assignment operation and just print:
( lapply(iris[numVars], round, digits = 2) )
Or set your digits argument to print:
print( head(iris), digits=1)
Or did I miss something?
--
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list