|
Hi all,
I have a list of numbers, e.g., X = c(60593.23, 71631.17, 75320.1), and want to round them so the output is Y = c(60000, 80000, 80000). I tried Y<-round(X,-4), but it gives me Y = c(60000, 70000, 80000). Do anybody know how to round up a number to 10^4? Thank you in advance. Wendy |
|
On Nov 1, 2011, at 1:07 PM, Wendy wrote: > Hi all, > > I have a list of numbers, e.g., X = c(60593.23, 71631.17, 75320.1), > and want > to round them so the output is Y = c(60000, 80000, 80000). Under what notion of "rounding" would that be the result? > I tried > Y<-round(X,-4), but it gives me Y = c(60000, 70000, 80000). Do > anybody know > how to round up a number to 10^4? > > Thank you in advance. -- David Winsemius, MD Heritage Laboratories West Hartford, CT ______________________________________________ [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. |
|
Could you divide by your desired order of magnitude, use ceiling and then re-multiply?
Michael On Nov 1, 2011, at 3:42 PM, David Winsemius <[hidden email]> wrote: > > On Nov 1, 2011, at 1:07 PM, Wendy wrote: > >> Hi all, >> >> I have a list of numbers, e.g., X = c(60593.23, 71631.17, 75320.1), and want >> to round them so the output is Y = c(60000, 80000, 80000). > > Under what notion of "rounding" would that be the result? > >> I tried >> Y<-round(X,-4), but it gives me Y = c(60000, 70000, 80000). Do anybody know >> how to round up a number to 10^4? >> >> Thank you in advance. > > > -- > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > > ______________________________________________ > [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. ______________________________________________ [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. |
|
In reply to this post by David Winsemius
Or does the middle number have two digits switched? 76131.17 would
round up to 80000 very nicely. -- Clint Bowman INTERNET: [hidden email] Air Quality Modeler INTERNET: [hidden email] Department of Ecology VOICE: (360) 407-6815 PO Box 47600 FAX: (360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels: 300 Desmond Drive, Lacey, WA 98503-1274 On Tue, 1 Nov 2011, David Winsemius wrote: > > On Nov 1, 2011, at 1:07 PM, Wendy wrote: > >> Hi all, >> >> I have a list of numbers, e.g., X = c(60593.23, 71631.17, 75320.1), and >> want >> to round them so the output is Y = c(60000, 80000, 80000). > > Under what notion of "rounding" would that be the result? > >> I tried >> Y<-round(X,-4), but it gives me Y = c(60000, 70000, 80000). Do anybody know >> how to round up a number to 10^4? >> >> Thank you in advance. > > > ______________________________________________ [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. |
|
In reply to this post by David Winsemius
Yes, I agree with David that this looks like an error.
However, for fun, one might ask: what is the fewest number of R elementary math operations that would produce such a result -- this might be good for clever 6th or 7th graders, for example. For here, I leave this as an exercise for the reader. -- Bert On Tue, Nov 1, 2011 at 12:42 PM, David Winsemius <[hidden email]>wrote: > > On Nov 1, 2011, at 1:07 PM, Wendy wrote: > > Hi all, >> >> I have a list of numbers, e.g., X = c(60593.23, 71631.17, 75320.1), and >> want >> to round them so the output is Y = c(60000, 80000, 80000). >> > > Under what notion of "rounding" would that be the result? > > I tried >> Y<-round(X,-4), but it gives me Y = c(60000, 70000, 80000). Do anybody >> know >> how to round up a number to 10^4? >> >> Thank you in advance. >> > > > -- > David Winsemius, MD > Heritage Laboratories > West Hartford, CT > > ______________________________**________________ > [hidden email] mailing list > https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/** > posting-guide.html <http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[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. |
|
Also be aware of the IEEE standard of rounding to even:
> round(61000, -4) [1] 60000 > round(62000, -4) [1] 60000 > round(65000, -4) [1] 60000 > round(66000, -4) [1] 70000 > round(76000, -4) [1] 80000 > round(75000, -4) [1] 80000 > notice what 65000 rounds to and what 75000 rounds to. On Tue, Nov 1, 2011 at 4:13 PM, Bert Gunter <[hidden email]> wrote: > Yes, I agree with David that this looks like an error. > > However, for fun, one might ask: what is the fewest number of R elementary > math operations that would produce such a result -- this might be good for > clever 6th or 7th graders, for example. > > For here, I leave this as an exercise for the reader. > > -- Bert > > On Tue, Nov 1, 2011 at 12:42 PM, David Winsemius <[hidden email]>wrote: > >> >> On Nov 1, 2011, at 1:07 PM, Wendy wrote: >> >> Hi all, >>> >>> I have a list of numbers, e.g., X = c(60593.23, 71631.17, 75320.1), and >>> want >>> to round them so the output is Y = c(60000, 80000, 80000). >>> >> >> Under what notion of "rounding" would that be the result? >> >> I tried >>> Y<-round(X,-4), but it gives me Y = c(60000, 70000, 80000). Do anybody >>> know >>> how to round up a number to 10^4? >>> >>> Thank you in advance. >>> >> >> >> -- >> David Winsemius, MD >> Heritage Laboratories >> West Hartford, CT >> >> ______________________________**________________ >> [hidden email] mailing list >> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> >> PLEASE do read the posting guide http://www.R-project.org/** >> posting-guide.html <http://www.R-project.org/posting-guide.html> >> and provide commented, minimal, self-contained, reproducible code. >> > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm > > [[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. > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. ______________________________________________ [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. |
|
In reply to this post by Bert Gunter
Bert,
How do you define "elementary"? And, do we play this like "Name That Tune"? "Bert, I can do that calculation in X operations." Or, maybe like Jeopardy, "What is the number X?" Or maybe we could play "Are You Smarter Than a Seventh-Grader?" I'm just asking. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 > -----Original Message----- > From: [hidden email] [mailto:r-help-bounces@r- > project.org] On Behalf Of Bert Gunter > Sent: Tuesday, November 01, 2011 1:13 PM > To: David Winsemius > Cc: [hidden email]; Wendy > Subject: Re: [R] round up a number to 10^4 > > Yes, I agree with David that this looks like an error. > > However, for fun, one might ask: what is the fewest number of R > elementary > math operations that would produce such a result -- this might be good > for > clever 6th or 7th graders, for example. > > For here, I leave this as an exercise for the reader. > > -- Bert > > On Tue, Nov 1, 2011 at 12:42 PM, David Winsemius > <[hidden email]>wrote: > > > > > On Nov 1, 2011, at 1:07 PM, Wendy wrote: > > > > Hi all, > >> > >> I have a list of numbers, e.g., X = c(60593.23, 71631.17, 75320.1), > and > >> want > >> to round them so the output is Y = c(60000, 80000, 80000). > >> > > > > Under what notion of "rounding" would that be the result? > > > > I tried > >> Y<-round(X,-4), but it gives me Y = c(60000, 70000, 80000). Do > anybody > >> know > >> how to round up a number to 10^4? > >> > >> Thank you in advance. > >> > > > > > > -- > > David Winsemius, MD > > Heritage Laboratories > > West Hartford, CT > > > > ______________________________**________________ > > [hidden email] mailing list > > https://stat.ethz.ch/mailman/**listinfo/r- > help<https://stat.ethz.ch/mailman/listinfo/r-help> > > PLEASE do read the posting guide http://www.R-project.org/** > > posting-guide.html <http://www.R-project.org/posting-guide.html> > > and provide commented, minimal, self-contained, reproducible code. > > > > > > -- > > Bert Gunter > Genentech Nonclinical Biostatistics > > Internal Contact Info: > Phone: 467-7374 > Website: > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb- > biostatistics/pdb-ncb-home.htm > > [[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. ______________________________________________ [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. |
|
In reply to this post by Wendy
Works in the newly released 2.14.0:
> X = c(60593.23, 71631.17, 75320.1) > round(X, -4) [1] 60000 70000 80000 Dennis On Tue, Nov 1, 2011 at 10:07 AM, Wendy <[hidden email]> wrote: > Hi all, > > I have a list of numbers, e.g., X = c(60593.23, 71631.17, 75320.1), and want > to round them so the output is Y = c(60000, 80000, 80000). I tried > Y<-round(X,-4), but it gives me Y = c(60000, 70000, 80000). Do anybody know > how to round up a number to 10^4? > > Thank you in advance. > > Wendy > > > -- > View this message in context: http://r.789695.n4.nabble.com/round-up-a-number-to-10-4-tp3964394p3964394.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > [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. > ______________________________________________ [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. |
| Powered by Nabble | Edit this page |
