Quantcast

trunc function

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

trunc function

Luis Felipe Parra
Hello. I would like to know if there exists in R a function like trunc but
where i can choose how many decimal places can I stay with in the number I
have (sort of the same as the trunc function in excel). I would like, for
example if I have the number 0.974678 and I choose to stay with 3 decimal
places to have as ouput 0.974.

Thank you

Felipe Parra

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: trunc function

Carlos Ortega
Hola Felipe,

Sí, la función es round().

Por cierto, tenemos una lista de ayuda del R en español.
Te puedes suscribir aquí:

https://stat.ethz.ch/mailman/listinfo/r-help-es


Saludos,
Carlos Ortega
www.qualityexcellence.es

On Wed, Mar 9, 2011 at 10:36 AM, Luis Felipe Parra <
[hidden email]> wrote:

> Hello. I would like to know if there exists in R a function like trunc but
> where i can choose how many decimal places can I stay with in the number I
> have (sort of the same as the trunc function in excel). I would like, for
> example if I have the number 0.974678 and I choose to stay with 3 decimal
> places to have as ouput 0.974.
>
> Thank you
>
> Felipe Parra
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>
        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: trunc function

Petr Savicky-2
In reply to this post by Luis Felipe Parra
On Wed, Mar 09, 2011 at 05:36:35PM +0800, Luis Felipe Parra wrote:
> Hello. I would like to know if there exists in R a function like trunc but
> where i can choose how many decimal places can I stay with in the number I
> have (sort of the same as the trunc function in excel). I would like, for
> example if I have the number 0.974678 and I choose to stay with 3 decimal
> places to have as ouput 0.974.

Hello:

Try the following

  trunc.dig <- function(x, digits) trunc(x*10^digits)/10^digits

  trunc.dig(0.974678, 3)

  [1] 0.974

  trunc.dig(10.974999, 3)

  [1] 10.974

Hope this helps.

Petr Savicky.

______________________________________________
[hidden email] 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.
Loading...