Skip to content

truncation and approximation

3 messages · Francesco Miranda, Rui Barradas, alfonso.carfora at uniparthenope.it

#
Hello,

As for truncation, you can write a one line function:

dec_trunc <- function(x, digits = 0) trunc(x * 10^digits)/10^digits


As for approximation, maybe you're looking for ?signif.

Hope this helps,

Rui Barradas

Em 17-07-2013 18:41, Francesco Miranda escreveu:
#
Maybe you can use "round" and "trunc" functions

For example if you have a vector like this:


x<- c(3.000 3.125 3.250 3.375 3.500 3.625 3.750 3.875 4.000)

and you want to round the numbers to 2 decimals you can use:
[1] 3.00 3.12 3.25 3.38 3.50 3.62 3.75 3.88 4.00


if you want a numeric vector containing the integers formed by  
truncating the values in x
[1] 3 3 3 3 3 3 3 3 4

I'hope it'is useful to you
A.C.




Def. Quota Rui Barradas <ruipbarradas at sapo.pt>:
******************************************************************************	
IL MERITO DEGLI STUDENTI VIENE RICONOSCIUTO
 
Il 5 per mille all'Universita' degli Studi di Napoli "Parthenope" incrementa le borse di studio agli studenti - codice fiscale 80018240632
http://www.uniparthenope.it/index.php/5xmille 
 
http://www.uniparthenope.it/index.php/it/avvisi-sito-di-ateneo/2943-la-parthenope-premia-il-tuo-voto-di-diploma-ed-il-tuo-imegno-con-i-proventi-del-5-per-mille
 
Questa informativa e' inserita in automatico dal sistema al fine esclusivo della realizzazione dei fini istituzionali dell'ente.