sagarnikam123
2012-Mar-23 12:16 UTC
[R] how to convert digits to specified decimal vectors
> x[1] 7 8 9 10 11 12 convert such that 7.0000 8.0000 9.0000 10.000 11.000 12.000 total size of 5 digits for each value -- View this message in context: http://r.789695.n4.nabble.com/how-to-convert-digits-to-specified-decimal-vectors-tp4498588p4498588.html Sent from the R help mailing list archive at Nabble.com.
R. Michael Weylandt
2012-Mar-23 18:58 UTC
[R] how to convert digits to specified decimal vectors
format sprintf Michael On Fri, Mar 23, 2012 at 8:16 AM, sagarnikam123 <sagarnikam123 at gmail.com> wrote:>> x > [1] 7 8 9 10 11 12 > > convert such that > > 7.0000 > 8.0000 > 9.0000 > 10.000 > 11.000 > 12.000 > > total size of 5 digits for each value > > > -- > View this message in context: http://r.789695.n4.nabble.com/how-to-convert-digits-to-specified-decimal-vectors-tp4498588p4498588.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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.
sagarnikam123
2012-Mar-24 07:25 UTC
[R] how to convert digits to specified decimal vectors
yes sir i used format() function like> x<-c(3,5,6) >y<-format(x,nsmall=6) >y[1] "3.000000" "5.000000" "6.000000" but it again gives me same output> as.double(y[1])[1] 3 i want it in decimal style like 4.000 (i.e. without string format) -- View this message in context: http://r.789695.n4.nabble.com/how-to-convert-digits-to-specified-decimal-vectors-tp4498588p4500920.html Sent from the R help mailing list archive at Nabble.com.
Berend Hasselman
2012-Mar-24 08:31 UTC
[R] how to convert digits to specified decimal vectors
On 24-03-2012, at 08:25, sagarnikam123 wrote:> yes sir i used format() function like > >> x<-c(3,5,6) >> y<-format(x,nsmall=6) >> y > [1] "3.000000" "5.000000" "6.000000" > > but it again gives me same output >> as.double(y[1]) > [1] 3 >You are converting back to numeric and using the default print. Use cat(y) Berend> i want it in decimal style like 4.000 (i.e. without string format) > > > -- > View this message in context: http://r.789695.n4.nabble.com/how-to-convert-digits-to-specified-decimal-vectors-tp4498588p4500920.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org 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.