Hello I have a vector v=c(0.08844446,0.1744455,0.1379778,0.1209769,0.1573065,0.1134463,0.2074027) when i do sum(v) or 0.08844446+0.1744455+0.1379778+0.1209769+0.1573065+0.1134463+0.2074027 i am getting output as 1 But if i add them manually i get 1.00000026 I do not want to round of my value since it effect my code further Can anyone suggest how can i avoid this. Thanks & Regards Niharika Singhal [[alternative HTML version deleted]]
On 2017-08-22 9:26 AM, niharika singhal wrote:> Hello I have a vector > v=c(0.08844446,0.1744455,0.1379778,0.1209769,0.1573065,0.1134463,0.2074027) > when i do > sum(v) > or > 0.08844446+0.1744455+0.1379778+0.1209769+0.1573065+0.1134463+0.2074027 > i am getting output as 1No:? That's only the display: > sum(v)-1 [1] 1.6e-07 ????? hope this helps.? Spencer> But if i add them manually i get > 1.00000026 > I do not want to round of my value since it effect my code further > Can anyone suggest how can i avoid this. > > Thanks & Regards > Niharika Singhal > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
... and following up on Spencer's answer, see the "digits" argument of ?options and ?print.default. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Aug 22, 2017 at 7:30 AM, Spencer Graves <spencer.graves at effectivedefense.org> wrote:> > > On 2017-08-22 9:26 AM, niharika singhal wrote: >> >> Hello I have a vector >> >> v=c(0.08844446,0.1744455,0.1379778,0.1209769,0.1573065,0.1134463,0.2074027) >> when i do >> sum(v) >> or >> 0.08844446+0.1744455+0.1379778+0.1209769+0.1573065+0.1134463+0.2074027 >> i am getting output as 1 > > > > No: That's only the display: > > >> sum(v)-1 > [1] 1.6e-07 > > > hope this helps. Spencer > > >> But if i add them manually i get >> 1.00000026 >> I do not want to round of my value since it effect my code further >> Can anyone suggest how can i avoid this. >> >> Thanks & Regards >> Niharika Singhal >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. > > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.
Le 22/08/2017 ? 16:26, niharika singhal a ?crit?:> Hello I have a vector > v=c(0.08844446,0.1744455,0.1379778,0.1209769,0.1573065,0.1134463,0.2074027) > when i do > sum(v) > or > 0.08844446+0.1744455+0.1379778+0.1209769+0.1573065+0.1134463+0.2074027 > i am getting output as 1 > But if i add them manually i get > 1.00000026 > I do not want to round of my value since it effect my code further > Can anyone suggest how can i avoid this. > > Thanks & Regards > Niharika Singhal > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >> print(sum(v), digits = 12) [1] 1.00000016