Re: [R] Format printing with R
And you will probably want to read the details of the ?round help, so you understand how it handles 5 rounding. It is a little more complicated than some of us learned in school. On 11/22/2022 4:24 AM, Steven T. Yen wrote: Thanks to all. And yes, Ivan, round() did it: > dput(head(Mean)) c(afactfem = 0.310796641158209, afactblk = 0.188030178893171, age = 45.3185794338312, nodiscfem = 0.506637018185968, discfem = 0.493362981814032, notradgrol = 0.702915000493879) > dput(head(Std.dev)) c(afactfem = 0.462819715443265, afactblk = 0.390736267472797, age = 16.3136348021933, nodiscfem = 0.499955948049025, discfem = 0.499955948049025, notradgrol = 0.456974290933931) > round(cbind(Mean,Std.dev),2)[1:10,] Mean Std.dev afactfem 0.31 0.46 afactblk 0.19 0.39 age 45.32 16.31 nodiscfem 0.51 0.50 discfem 0.49 0.50 notradgrol 0.70 0.46 tradgrol 0.30 0.46 nofemnopol 0.80 0.40 femnopol 0.20 0.40 nopreshurt 0.66 0.47 On 11/22/2022 3:08 PM, Ivan Krylov wrote: On Tue, 22 Nov 2022 08:15:57 +0800 "Steven T. Yen" wrote: Thanks to all, but no, signif() did not work: It worked, just didn't do what you wanted it to do. I think you want round(), not signif(). Some of your numbers (45.3185794) will be rounded to 4 significant digits and others (0.096) will be rounded to 1 significant digit, but the number of decimal places will be 2. __ R-help@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@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.
Re: [R] Format printing with R
Thanks to all. And yes, Ivan, round() did it: > dput(head(Mean)) c(afactfem = 0.310796641158209, afactblk = 0.188030178893171, age = 45.3185794338312, nodiscfem = 0.506637018185968, discfem = 0.493362981814032, notradgrol = 0.702915000493879) > dput(head(Std.dev)) c(afactfem = 0.462819715443265, afactblk = 0.390736267472797, age = 16.3136348021933, nodiscfem = 0.499955948049025, discfem = 0.499955948049025, notradgrol = 0.456974290933931) > round(cbind(Mean,Std.dev),2)[1:10,] Mean Std.dev afactfem 0.31 0.46 afactblk 0.19 0.39 age 45.32 16.31 nodiscfem 0.51 0.50 discfem 0.49 0.50 notradgrol 0.70 0.46 tradgrol 0.30 0.46 nofemnopol 0.80 0.40 femnopol 0.20 0.40 nopreshurt 0.66 0.47 On 11/22/2022 3:08 PM, Ivan Krylov wrote: On Tue, 22 Nov 2022 08:15:57 +0800 "Steven T. Yen" wrote: Thanks to all, but no, signif() did not work: It worked, just didn't do what you wanted it to do. I think you want round(), not signif(). Some of your numbers (45.3185794) will be rounded to 4 significant digits and others (0.096) will be rounded to 1 significant digit, but the number of decimal places will be 2. __ R-help@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.
Re: [R] Format printing with R
On Tue, 22 Nov 2022 08:15:57 +0800 "Steven T. Yen" wrote: > Thanks to all, but no, signif() did not work: It worked, just didn't do what you wanted it to do. I think you want round(), not signif(). Some of your numbers (45.3185794) will be rounded to 4 significant digits and others (0.096) will be rounded to 1 significant digit, but the number of decimal places will be 2. -- Best regards, Ivan __ R-help@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.
Re: [R] Format printing with R
??? > vals <- signif(cbind(c(.123,.0123), c(1.23,.00123)), digits = 2) > print(vals) [,1] [,2] [1,] 0.120 1.2000 [2,] 0.012 0.0012 2 *significant* digits, but enough digits to right of decimal point to **allow** the two significant digits to appear and have all numbers in a column line up neatly. If you don't want them to line up, you will probably have to use cat() to print row by row. > for(i in 1:2)cat(vals[i,],"\n",sep = ' ') 0.12 1.2 0.012 0.0012 Further nuances can be found in ?format, which again tries to line things up in columns. -- Bert On Mon, Nov 21, 2022 at 4:58 PM Jeff Newmiller wrote: > > Andrew's example works for him and for me. > > If you want help, provide the output of > > dput(head(Mean)) > dput(head(Std.dev)) > > > On November 21, 2022 4:15:57 PM PST, "Steven T. Yen" wrote: > >Thanks to all, but no, signif() did not work: > > > >> print(signif(cbind(Mean,Std.dev),digits=2)) > >Mean Std.dev > > [1,] 0.3100.46 > > [2,] 0.1900.39 > > [3,] 45.000 16.00 > > [4,] 0.5100.50 > > [5,] 0.4900.50 > > [6,] 0.7000.46 > > > >On 11/22/2022 5:41 AM, Andrew Simmons wrote: > >> For print(), digits is the minimal number of significant digits. In > >> your case, rounding the first column to the 3rd decimal place gives at > >> least 2 sigfigs and rounding the second column to the 2nd decimal > >> place. > >> > >> If you want to print all numbers to two significant digits, regardless > >> of what other numbers are in the column, use signif() before print(): > >> > >> Mean <- c(0.3107966, 0.1880302, 45.3185794, 0.506637, 0.493363, > >> 0.702915, 0.297085, 0.7967066, 0.2032934, 0.6582301, 0.3417699, > >> 0.7262913, 0.2737087, 0.6415484, 0.3584516, 0.9110264, 0.0889736, > >> 0.5211453, 0.4788547, 0.5481055, 0.4518945, 0.913509, 0.086491, > >> 0.8727269, 0.1272731, 0.1015717, 0.6043692, 0.2940592, 0.2735274, > >> 0.3777426, 0.34873, 0.1603127, 0.1723783, 0.1230961, 0.1779381, > >> 0.0964334, 0.1584698, 0.1113717, 0.3349813, 0.4081109, 0.2569078, > >> 0.1034356, 0.6741233, 0.1254412, 0.096, 0.0587457, 0.4401115, > >> 0.4689114, 0.0322313, 0.5907618, 0.1591195, 0.1132923, 0.1124207, > >> 0.0244058, 0.7058787, 0.2941213, 0.0746892, 0.474911, 0.3471837, > >> 0.0435036, 0.0597126, 0.0478775, 0.1152615, 0.2074968, 0.2440626, > >> 0.1605995, 0.0804598, 0.1442422, 0.3443231, 0.428056, 0.0528221, > >> 0.0805222, 0.0457169, 0.0485596, 0.1333443, 0.0932917, 0.0653987, > >> 0.0573934, 0.1399086, 0.0887337, 0.0984479, 0.0914421, 0.1155505, > >> 0.1363764, 0.113457, 1.2985286) > >> Std.dev <- c(0.46282, 0.390736, 16.313635, 0.499956, 0.499956, > >> 0.456974, 0.456974, 0.402449, 0.402449, 0.474303, 0.474303, 0.445861, > >> 0.445861, 0.479546, 0.479546, 0.284706, 0.284706, 0.499553, 0.499553, > >> 0.49768, 0.49768, 0.281088, 0.281088, 0.333279, 0.333279, 0.302084, > >> 0.488986, 0.455619, 0.445769, 0.484823, 0.476568, 0.366896, 0.377709, > >> 0.328547, 0.382461, 0.295185, 0.365181, 0.314592, 0.471984, 0.491484, > >> 0.436928, 0.304527, 0.468701, 0.331218, 0.295958, 0.235148, 0.4964, > >> 0.499033, 0.176614, 0.491693, 0.365787, 0.31695, 0.315883, 0.154305, > >> 0.455647, 0.455647, 0.262889, 0.49937, 0.476075, 0.203988, 0.236954, > >> 0.213507, 0.319337, 0.405514, 0.42953, 0.367161, 0.272004, 0.351335, > >> 0.475147, 0.494797, 0.223678, 0.2721, 0.20887, 0.214945, 0.339946, > >> 0.290841, 0.247228, 0.232593, 0.346892, 0.284359, 0.297919, 0.288237, > >> 0.319685, 0.343188, 0.317151, 0.739096) > >> print(signif(cbind(Mean, Std.dev), 2)) > >> > >> which looks like: > >> > >>> print(signif(cbind(Mean, Std.dev), 2)) > >> Mean Std.dev > >> [1,] 0.3100.46 > >> [2,] 0.1900.39 > >> [3,] 45.000 16.00 > >> [4,] 0.5100.50 > >> [5,] 0.4900.50 > >> [6,] 0.7000.46 > >> [7,] 0.3000.46 > >> [8,] 0.8000.40 > >> [9,] 0.2000.40 > >> [10,] 0.6600.47 > >> [11,] 0.3400.47 > >> [12,] 0.7300.45 > >> [13,] 0.2700.45 > >> [14,] 0.6400.48 > >> [15,] 0.3600.48 > >> [16,] 0.9100.28 > >> [17,] 0.0890.28 > >> [18,] 0.5200.50 > >> [19,] 0.4800.50 > >> [20,] 0.5500.50 > >> [21,] 0.4500.50 > >> [22,] 0.9100.28 > >> [23,] 0.0860.28 > >> [24,] 0.8700.33 > >> [25,] 0.1300.33 > >> [26,] 0.1000.30 > >> [27,] 0.6000.49 > >> [28,] 0.2900.46 > >> [29,] 0.2700.45 > >> [30,] 0.3800.48 > >> [31,] 0.3500.48 > >> [32,] 0.1600.37 > >> [33,] 0.1700.38 > >> [34,] 0.1200.33 > >> [35,] 0.1800.38 > >> [36,] 0.0960.30 > >> [37,] 0.1600.37 > >> [38,] 0.1100.31 > >> [39,] 0.3300.47 > >> [40,] 0.4100.49 > >> [41,] 0.2600.44 > >> [42,] 0.1000.30 > >> [43,] 0.6700.47 > >> [44,] 0.1300.33 > >> [45,] 0.0970.30 > >> [46,] 0.0590.24 > >> [47,] 0.4400.50
Re: [R] Format printing with R
Andrew's example works for him and for me. If you want help, provide the output of dput(head(Mean)) dput(head(Std.dev)) On November 21, 2022 4:15:57 PM PST, "Steven T. Yen" wrote: >Thanks to all, but no, signif() did not work: > >> print(signif(cbind(Mean,Std.dev),digits=2)) > Mean Std.dev > [1,] 0.310 0.46 > [2,] 0.190 0.39 > [3,] 45.000 16.00 > [4,] 0.510 0.50 > [5,] 0.490 0.50 > [6,] 0.700 0.46 > >On 11/22/2022 5:41 AM, Andrew Simmons wrote: >> For print(), digits is the minimal number of significant digits. In >> your case, rounding the first column to the 3rd decimal place gives at >> least 2 sigfigs and rounding the second column to the 2nd decimal >> place. >> >> If you want to print all numbers to two significant digits, regardless >> of what other numbers are in the column, use signif() before print(): >> >> Mean <- c(0.3107966, 0.1880302, 45.3185794, 0.506637, 0.493363, >> 0.702915, 0.297085, 0.7967066, 0.2032934, 0.6582301, 0.3417699, >> 0.7262913, 0.2737087, 0.6415484, 0.3584516, 0.9110264, 0.0889736, >> 0.5211453, 0.4788547, 0.5481055, 0.4518945, 0.913509, 0.086491, >> 0.8727269, 0.1272731, 0.1015717, 0.6043692, 0.2940592, 0.2735274, >> 0.3777426, 0.34873, 0.1603127, 0.1723783, 0.1230961, 0.1779381, >> 0.0964334, 0.1584698, 0.1113717, 0.3349813, 0.4081109, 0.2569078, >> 0.1034356, 0.6741233, 0.1254412, 0.096, 0.0587457, 0.4401115, >> 0.4689114, 0.0322313, 0.5907618, 0.1591195, 0.1132923, 0.1124207, >> 0.0244058, 0.7058787, 0.2941213, 0.0746892, 0.474911, 0.3471837, >> 0.0435036, 0.0597126, 0.0478775, 0.1152615, 0.2074968, 0.2440626, >> 0.1605995, 0.0804598, 0.1442422, 0.3443231, 0.428056, 0.0528221, >> 0.0805222, 0.0457169, 0.0485596, 0.1333443, 0.0932917, 0.0653987, >> 0.0573934, 0.1399086, 0.0887337, 0.0984479, 0.0914421, 0.1155505, >> 0.1363764, 0.113457, 1.2985286) >> Std.dev <- c(0.46282, 0.390736, 16.313635, 0.499956, 0.499956, >> 0.456974, 0.456974, 0.402449, 0.402449, 0.474303, 0.474303, 0.445861, >> 0.445861, 0.479546, 0.479546, 0.284706, 0.284706, 0.499553, 0.499553, >> 0.49768, 0.49768, 0.281088, 0.281088, 0.333279, 0.333279, 0.302084, >> 0.488986, 0.455619, 0.445769, 0.484823, 0.476568, 0.366896, 0.377709, >> 0.328547, 0.382461, 0.295185, 0.365181, 0.314592, 0.471984, 0.491484, >> 0.436928, 0.304527, 0.468701, 0.331218, 0.295958, 0.235148, 0.4964, >> 0.499033, 0.176614, 0.491693, 0.365787, 0.31695, 0.315883, 0.154305, >> 0.455647, 0.455647, 0.262889, 0.49937, 0.476075, 0.203988, 0.236954, >> 0.213507, 0.319337, 0.405514, 0.42953, 0.367161, 0.272004, 0.351335, >> 0.475147, 0.494797, 0.223678, 0.2721, 0.20887, 0.214945, 0.339946, >> 0.290841, 0.247228, 0.232593, 0.346892, 0.284359, 0.297919, 0.288237, >> 0.319685, 0.343188, 0.317151, 0.739096) >> print(signif(cbind(Mean, Std.dev), 2)) >> >> which looks like: >> >>> print(signif(cbind(Mean, Std.dev), 2)) >> Mean Std.dev >> [1,] 0.3100.46 >> [2,] 0.1900.39 >> [3,] 45.000 16.00 >> [4,] 0.5100.50 >> [5,] 0.4900.50 >> [6,] 0.7000.46 >> [7,] 0.3000.46 >> [8,] 0.8000.40 >> [9,] 0.2000.40 >> [10,] 0.6600.47 >> [11,] 0.3400.47 >> [12,] 0.7300.45 >> [13,] 0.2700.45 >> [14,] 0.6400.48 >> [15,] 0.3600.48 >> [16,] 0.9100.28 >> [17,] 0.0890.28 >> [18,] 0.5200.50 >> [19,] 0.4800.50 >> [20,] 0.5500.50 >> [21,] 0.4500.50 >> [22,] 0.9100.28 >> [23,] 0.0860.28 >> [24,] 0.8700.33 >> [25,] 0.1300.33 >> [26,] 0.1000.30 >> [27,] 0.6000.49 >> [28,] 0.2900.46 >> [29,] 0.2700.45 >> [30,] 0.3800.48 >> [31,] 0.3500.48 >> [32,] 0.1600.37 >> [33,] 0.1700.38 >> [34,] 0.1200.33 >> [35,] 0.1800.38 >> [36,] 0.0960.30 >> [37,] 0.1600.37 >> [38,] 0.1100.31 >> [39,] 0.3300.47 >> [40,] 0.4100.49 >> [41,] 0.2600.44 >> [42,] 0.1000.30 >> [43,] 0.6700.47 >> [44,] 0.1300.33 >> [45,] 0.0970.30 >> [46,] 0.0590.24 >> [47,] 0.4400.50 >> [48,] 0.4700.50 >> [49,] 0.0320.18 >> [50,] 0.5900.49 >> [51,] 0.1600.37 >> [52,] 0.1100.32 >> [53,] 0.1100.32 >> [54,] 0.0240.15 >> [55,] 0.7100.46 >> [56,] 0.2900.46 >> [57,] 0.0750.26 >> [58,] 0.4700.50 >> [59,] 0.3500.48 >> [60,] 0.0440.20 >> [61,] 0.0600.24 >> [62,] 0.0480.21 >> [63,] 0.1200.32 >> [64,] 0.2100.41 >> [65,] 0.2400.43 >> [66,] 0.1600.37 >> [67,] 0.0800.27 >> [68,] 0.1400.35 >> [69,] 0.3400.48 >> [70,] 0.4300.49 >> [71,] 0.0530.22 >> [72,] 0.0810.27 >> [73,] 0.0460.21 >> [74,] 0.0490.21 >> [75,] 0.1300.34 >> [76,] 0.0930.29 >> [77,] 0.0650.25 >> [78,] 0.0570.23 >> [79,] 0.1400.35 >> [80,] 0.0890.28 >> [81,] 0.0980.30 >> [82,] 0.0910.2
Re: [R] Format printing with R
Thanks to all, but no, signif() did not work: > print(signif(cbind(Mean,Std.dev),digits=2)) Mean Std.dev [1,] 0.310 0.46 [2,] 0.190 0.39 [3,] 45.000 16.00 [4,] 0.510 0.50 [5,] 0.490 0.50 [6,] 0.700 0.46 On 11/22/2022 5:41 AM, Andrew Simmons wrote: For print(), digits is the minimal number of significant digits. In your case, rounding the first column to the 3rd decimal place gives at least 2 sigfigs and rounding the second column to the 2nd decimal place. If you want to print all numbers to two significant digits, regardless of what other numbers are in the column, use signif() before print(): Mean <- c(0.3107966, 0.1880302, 45.3185794, 0.506637, 0.493363, 0.702915, 0.297085, 0.7967066, 0.2032934, 0.6582301, 0.3417699, 0.7262913, 0.2737087, 0.6415484, 0.3584516, 0.9110264, 0.0889736, 0.5211453, 0.4788547, 0.5481055, 0.4518945, 0.913509, 0.086491, 0.8727269, 0.1272731, 0.1015717, 0.6043692, 0.2940592, 0.2735274, 0.3777426, 0.34873, 0.1603127, 0.1723783, 0.1230961, 0.1779381, 0.0964334, 0.1584698, 0.1113717, 0.3349813, 0.4081109, 0.2569078, 0.1034356, 0.6741233, 0.1254412, 0.096, 0.0587457, 0.4401115, 0.4689114, 0.0322313, 0.5907618, 0.1591195, 0.1132923, 0.1124207, 0.0244058, 0.7058787, 0.2941213, 0.0746892, 0.474911, 0.3471837, 0.0435036, 0.0597126, 0.0478775, 0.1152615, 0.2074968, 0.2440626, 0.1605995, 0.0804598, 0.1442422, 0.3443231, 0.428056, 0.0528221, 0.0805222, 0.0457169, 0.0485596, 0.1333443, 0.0932917, 0.0653987, 0.0573934, 0.1399086, 0.0887337, 0.0984479, 0.0914421, 0.1155505, 0.1363764, 0.113457, 1.2985286) Std.dev <- c(0.46282, 0.390736, 16.313635, 0.499956, 0.499956, 0.456974, 0.456974, 0.402449, 0.402449, 0.474303, 0.474303, 0.445861, 0.445861, 0.479546, 0.479546, 0.284706, 0.284706, 0.499553, 0.499553, 0.49768, 0.49768, 0.281088, 0.281088, 0.333279, 0.333279, 0.302084, 0.488986, 0.455619, 0.445769, 0.484823, 0.476568, 0.366896, 0.377709, 0.328547, 0.382461, 0.295185, 0.365181, 0.314592, 0.471984, 0.491484, 0.436928, 0.304527, 0.468701, 0.331218, 0.295958, 0.235148, 0.4964, 0.499033, 0.176614, 0.491693, 0.365787, 0.31695, 0.315883, 0.154305, 0.455647, 0.455647, 0.262889, 0.49937, 0.476075, 0.203988, 0.236954, 0.213507, 0.319337, 0.405514, 0.42953, 0.367161, 0.272004, 0.351335, 0.475147, 0.494797, 0.223678, 0.2721, 0.20887, 0.214945, 0.339946, 0.290841, 0.247228, 0.232593, 0.346892, 0.284359, 0.297919, 0.288237, 0.319685, 0.343188, 0.317151, 0.739096) print(signif(cbind(Mean, Std.dev), 2)) which looks like: print(signif(cbind(Mean, Std.dev), 2)) Mean Std.dev [1,] 0.3100.46 [2,] 0.1900.39 [3,] 45.000 16.00 [4,] 0.5100.50 [5,] 0.4900.50 [6,] 0.7000.46 [7,] 0.3000.46 [8,] 0.8000.40 [9,] 0.2000.40 [10,] 0.6600.47 [11,] 0.3400.47 [12,] 0.7300.45 [13,] 0.2700.45 [14,] 0.6400.48 [15,] 0.3600.48 [16,] 0.9100.28 [17,] 0.0890.28 [18,] 0.5200.50 [19,] 0.4800.50 [20,] 0.5500.50 [21,] 0.4500.50 [22,] 0.9100.28 [23,] 0.0860.28 [24,] 0.8700.33 [25,] 0.1300.33 [26,] 0.1000.30 [27,] 0.6000.49 [28,] 0.2900.46 [29,] 0.2700.45 [30,] 0.3800.48 [31,] 0.3500.48 [32,] 0.1600.37 [33,] 0.1700.38 [34,] 0.1200.33 [35,] 0.1800.38 [36,] 0.0960.30 [37,] 0.1600.37 [38,] 0.1100.31 [39,] 0.3300.47 [40,] 0.4100.49 [41,] 0.2600.44 [42,] 0.1000.30 [43,] 0.6700.47 [44,] 0.1300.33 [45,] 0.0970.30 [46,] 0.0590.24 [47,] 0.4400.50 [48,] 0.4700.50 [49,] 0.0320.18 [50,] 0.5900.49 [51,] 0.1600.37 [52,] 0.1100.32 [53,] 0.1100.32 [54,] 0.0240.15 [55,] 0.7100.46 [56,] 0.2900.46 [57,] 0.0750.26 [58,] 0.4700.50 [59,] 0.3500.48 [60,] 0.0440.20 [61,] 0.0600.24 [62,] 0.0480.21 [63,] 0.1200.32 [64,] 0.2100.41 [65,] 0.2400.43 [66,] 0.1600.37 [67,] 0.0800.27 [68,] 0.1400.35 [69,] 0.3400.48 [70,] 0.4300.49 [71,] 0.0530.22 [72,] 0.0810.27 [73,] 0.0460.21 [74,] 0.0490.21 [75,] 0.1300.34 [76,] 0.0930.29 [77,] 0.0650.25 [78,] 0.0570.23 [79,] 0.1400.35 [80,] 0.0890.28 [81,] 0.0980.30 [82,] 0.0910.29 [83,] 0.1200.32 [84,] 0.1400.34 [85,] 0.1100.32 [86,] 1.3000.74 R will still print 3 decimal places for the third column since it wants them to be of the same format, but each number is 2 sigfigs. On Mon, Nov 21, 2022 at 3:41 PM Steven T. Yen via R-help wrote: Hi, I have two variables with 86 observations each. Below I print with the print command with digit=2. But, I am getting three decimal places for my first variable and two for the second. Please help. Thanks. > cbind(Mean,Std.dev) Mean Std.dev [1,] 0.310796
Re: [R] Format printing with R
Hi All How about data.frame or zapsmall. Apologies for the small set but it seems to show the point Mean = c(0.311,0.188,45.319) sdd = c(0.36,0.39,16.31) data.frame(Mean = Mean, St.dev = sdd) Mean St.dev 1 0.311 0.36 2 0.188 0.39 3 45.319 16.31 print(data.frame(Mean = Mean, St.dev = sdd),digits = 2) Mean St.dev 1 0.31 0.36 2 0.19 0.39 3 45.32 16.31 zapsmall(data.frame(Mean = Mean, St.dev = sdd),digits = 4) Mean St.dev 1 0.31 0.36 2 0.19 0.39 3 45.32 16.31 zapsmall(cbind(Mean = Mean,sdd),digits = 4) Mean sdd [1,] 0.31 0.36 [2,] 0.19 0.39 [3,] 45.32 16.31 Regards Duncan Mackay -- Original Message -- From: "Jim Lemon" To: "Steven T. Yen" Cc: "R-help Mailing List" Sent: Tuesday, 22 Nov, 2022 At 8:09 AM Subject: Re: [R] Format printing with R Hi Steven, I thought that the problem might be in the two large numbers, but using a subset (I didn't want to edit out all the line numbers), I get what I expected: sydf<-read.table(text="Mean Std.dev [1,] 0.3107966 0.462820 [2,] 0.1880302 0.390736 [3,] 45.3185794 16.313635 [4,] 0.5066370 0.499956 [5,] 0.4933630 0.499956 [6,] 0.7029150 0.456974 [7,] 0.2970850 0.456974 [8,] 0.7967066 0.402449 [9,] 0.2032934 0.402449", stringsAsFactors=FALSE,header=TRUE) print(sydf,digits=2) Mean Std.dev [1,] 0.310.46 [2,] 0.190.39 [3,] 45.32 16.31 [4,] 0.510.50 [5,] 0.490.50 [6,] 0.700.46 [7,] 0.300.46 [8,] 0.800.40 [9,] 0.200.40 I don't think it is your use of "cbind", but I didn't edit out Mean and Std.dev and try it. Jim On Tue, Nov 22, 2022 at 7:41 AM Steven T. Yen via R-help wrote: Hi, I have two variables with 86 observations each. Below I print with the print command with digit=2. But, I am getting three decimal places for my first variable and two for the second. Please help. Thanks. cbind(Mean,Std.dev) Mean Std.dev [1,] 0.3107966 0.462820 [2,] 0.1880302 0.390736 [3,] 45.3185794 16.313635 [4,] 0.5066370 0.499956 [5,] 0.4933630 0.499956 [6,] 0.7029150 0.456974 [7,] 0.2970850 0.456974 [8,] 0.7967066 0.402449 [9,] 0.2032934 0.402449 [10,] 0.6582301 0.474303 [11,] 0.3417699 0.474303 [12,] 0.7262913 0.445861 [13,] 0.2737087 0.445861 [14,] 0.6415484 0.479546 [15,] 0.3584516 0.479546 [16,] 0.9110264 0.284706 [17,] 0.0889736 0.284706 [18,] 0.5211453 0.499553 [19,] 0.4788547 0.499553 [20,] 0.5481055 0.497680 [21,] 0.4518945 0.497680 [22,] 0.9135090 0.281088 [23,] 0.0864910 0.281088 [24,] 0.8727269 0.333279 [25,] 0.1272731 0.333279 [26,] 0.1015717 0.302084 [27,] 0.6043692 0.488986 [28,] 0.2940592 0.455619 [29,] 0.2735274 0.445769 [30,] 0.3777426 0.484823 [31,] 0.3487300 0.476568 [32,] 0.1603127 0.366896 [33,] 0.1723783 0.377709 [34,] 0.1230961 0.328547 [35,] 0.1779381 0.382461 [36,] 0.0964334 0.295185 [37,] 0.1584698 0.365181 [38,] 0.1113717 0.314592 [39,] 0.3349813 0.471984 [40,] 0.4081109 0.491484 [41,] 0.2569078 0.436928 [42,] 0.1034356 0.304527 [43,] 0.6741233 0.468701 [44,] 0.1254412 0.331218 [45,] 0.096 0.295958 [46,] 0.0587457 0.235148 [47,] 0.4401115 0.496400 [48,] 0.4689114 0.499033 [49,] 0.0322313 0.176614 [50,] 0.5907618 0.491693 [51,] 0.1591195 0.365787 [52,] 0.1132923 0.316950 [53,] 0.1124207 0.315883 [54,] 0.0244058 0.154305 [55,] 0.7058787 0.455647 [56,] 0.2941213 0.455647 [57,] 0.0746892 0.262889 [58,] 0.4749110 0.499370 [59,] 0.3471837 0.476075 [60,] 0.0435036 0.203988 [61,] 0.0597126 0.236954 [62,] 0.0478775 0.213507 [63,] 0.1152615 0.319337 [64,] 0.2074968 0.405514 [65,] 0.2440626 0.429530 [66,] 0.1605995 0.367161 [67,] 0.0804598 0.272004 [68,] 0.1442422 0.351335 [69,] 0.3443231 0.475147 [70,] 0.4280560 0.494797 [71,] 0.0528221 0.223678 [72,] 0.0805222 0.272100 [73,] 0.0457169 0.208870 [74,] 0.0485596 0.214945 [75,] 0.1333443 0.339946 [76,] 0.0932917 0.290841 [77,] 0.0653987 0.247228 [78,] 0.0573934 0.232593 [79,] 0.1399086 0.346892 [80,] 0.0887337 0.284359 [81,] 0.0984479 0.297919 [82,] 0.0914421 0.288237 [83,] 0.1155505 0.319685 [84,] 0.1363764 0.343188 [85,] 0.1134570 0.317151 [86,] 1.2985286 0.739096 print(cbind(Mean,Std.dev),digits=2) Mean Std.dev [1,] 0.3110.46 [2,] 0.1880.39 [3,] 45.319 16.31 [4,] 0.5070.50 [5,] 0.4930.50 [6,] 0.7030.46 [7,] 0.2970.46 [8,] 0.7970.40 [9,] 0.2030.40 [10,] 0.6580.47 [11,] 0.3420.47 [12,] 0.7260.45 [13,] 0.2740.45 [14,] 0.6420.48 [15,] 0.3580.48 [16,] 0.9110.28 [17,] 0.0890.28 [18,] 0.5210.50 [19,] 0.4790.50 [20,] 0.5480.50 [21,] 0.4520.50 [22,] 0.9140.28 [23,] 0.0860.28 [24,] 0.8730.33 [25,] 0.1270.33 [26,] 0.1020.30 [27,] 0.6040.49 [28,] 0.2940.4
Re: [R] Format printing with R
For print(), digits is the minimal number of significant digits. In your case, rounding the first column to the 3rd decimal place gives at least 2 sigfigs and rounding the second column to the 2nd decimal place. If you want to print all numbers to two significant digits, regardless of what other numbers are in the column, use signif() before print(): Mean <- c(0.3107966, 0.1880302, 45.3185794, 0.506637, 0.493363, 0.702915, 0.297085, 0.7967066, 0.2032934, 0.6582301, 0.3417699, 0.7262913, 0.2737087, 0.6415484, 0.3584516, 0.9110264, 0.0889736, 0.5211453, 0.4788547, 0.5481055, 0.4518945, 0.913509, 0.086491, 0.8727269, 0.1272731, 0.1015717, 0.6043692, 0.2940592, 0.2735274, 0.3777426, 0.34873, 0.1603127, 0.1723783, 0.1230961, 0.1779381, 0.0964334, 0.1584698, 0.1113717, 0.3349813, 0.4081109, 0.2569078, 0.1034356, 0.6741233, 0.1254412, 0.096, 0.0587457, 0.4401115, 0.4689114, 0.0322313, 0.5907618, 0.1591195, 0.1132923, 0.1124207, 0.0244058, 0.7058787, 0.2941213, 0.0746892, 0.474911, 0.3471837, 0.0435036, 0.0597126, 0.0478775, 0.1152615, 0.2074968, 0.2440626, 0.1605995, 0.0804598, 0.1442422, 0.3443231, 0.428056, 0.0528221, 0.0805222, 0.0457169, 0.0485596, 0.1333443, 0.0932917, 0.0653987, 0.0573934, 0.1399086, 0.0887337, 0.0984479, 0.0914421, 0.1155505, 0.1363764, 0.113457, 1.2985286) Std.dev <- c(0.46282, 0.390736, 16.313635, 0.499956, 0.499956, 0.456974, 0.456974, 0.402449, 0.402449, 0.474303, 0.474303, 0.445861, 0.445861, 0.479546, 0.479546, 0.284706, 0.284706, 0.499553, 0.499553, 0.49768, 0.49768, 0.281088, 0.281088, 0.333279, 0.333279, 0.302084, 0.488986, 0.455619, 0.445769, 0.484823, 0.476568, 0.366896, 0.377709, 0.328547, 0.382461, 0.295185, 0.365181, 0.314592, 0.471984, 0.491484, 0.436928, 0.304527, 0.468701, 0.331218, 0.295958, 0.235148, 0.4964, 0.499033, 0.176614, 0.491693, 0.365787, 0.31695, 0.315883, 0.154305, 0.455647, 0.455647, 0.262889, 0.49937, 0.476075, 0.203988, 0.236954, 0.213507, 0.319337, 0.405514, 0.42953, 0.367161, 0.272004, 0.351335, 0.475147, 0.494797, 0.223678, 0.2721, 0.20887, 0.214945, 0.339946, 0.290841, 0.247228, 0.232593, 0.346892, 0.284359, 0.297919, 0.288237, 0.319685, 0.343188, 0.317151, 0.739096) print(signif(cbind(Mean, Std.dev), 2)) which looks like: > print(signif(cbind(Mean, Std.dev), 2)) Mean Std.dev [1,] 0.3100.46 [2,] 0.1900.39 [3,] 45.000 16.00 [4,] 0.5100.50 [5,] 0.4900.50 [6,] 0.7000.46 [7,] 0.3000.46 [8,] 0.8000.40 [9,] 0.2000.40 [10,] 0.6600.47 [11,] 0.3400.47 [12,] 0.7300.45 [13,] 0.2700.45 [14,] 0.6400.48 [15,] 0.3600.48 [16,] 0.9100.28 [17,] 0.0890.28 [18,] 0.5200.50 [19,] 0.4800.50 [20,] 0.5500.50 [21,] 0.4500.50 [22,] 0.9100.28 [23,] 0.0860.28 [24,] 0.8700.33 [25,] 0.1300.33 [26,] 0.1000.30 [27,] 0.6000.49 [28,] 0.2900.46 [29,] 0.2700.45 [30,] 0.3800.48 [31,] 0.3500.48 [32,] 0.1600.37 [33,] 0.1700.38 [34,] 0.1200.33 [35,] 0.1800.38 [36,] 0.0960.30 [37,] 0.1600.37 [38,] 0.1100.31 [39,] 0.3300.47 [40,] 0.4100.49 [41,] 0.2600.44 [42,] 0.1000.30 [43,] 0.6700.47 [44,] 0.1300.33 [45,] 0.0970.30 [46,] 0.0590.24 [47,] 0.4400.50 [48,] 0.4700.50 [49,] 0.0320.18 [50,] 0.5900.49 [51,] 0.1600.37 [52,] 0.1100.32 [53,] 0.1100.32 [54,] 0.0240.15 [55,] 0.7100.46 [56,] 0.2900.46 [57,] 0.0750.26 [58,] 0.4700.50 [59,] 0.3500.48 [60,] 0.0440.20 [61,] 0.0600.24 [62,] 0.0480.21 [63,] 0.1200.32 [64,] 0.2100.41 [65,] 0.2400.43 [66,] 0.1600.37 [67,] 0.0800.27 [68,] 0.1400.35 [69,] 0.3400.48 [70,] 0.4300.49 [71,] 0.0530.22 [72,] 0.0810.27 [73,] 0.0460.21 [74,] 0.0490.21 [75,] 0.1300.34 [76,] 0.0930.29 [77,] 0.0650.25 [78,] 0.0570.23 [79,] 0.1400.35 [80,] 0.0890.28 [81,] 0.0980.30 [82,] 0.0910.29 [83,] 0.1200.32 [84,] 0.1400.34 [85,] 0.1100.32 [86,] 1.3000.74 > R will still print 3 decimal places for the third column since it wants them to be of the same format, but each number is 2 sigfigs. On Mon, Nov 21, 2022 at 3:41 PM Steven T. Yen via R-help wrote: > > Hi, I have two variables with 86 observations each. Below I print with > the print command with digit=2. But, I am getting three decimal places > for my first variable and two for the second. Please help. Thanks. > > > cbind(Mean,Std.dev) > Mean Std.dev > [1,] 0.3107966 0.462820 > [2,] 0.1880302 0.390736 > [3,] 45.3185794 16.313635 > [4,] 0.5066370 0.499956 > [5,] 0.4933630 0.499956 > [6,] 0.7029150 0.456974 > [7,] 0.2970850 0.456974 > [8,] 0.7967066 0.402449 > [9,] 0.2032934 0.402449 > [10,] 0.6582301 0.474303 > [11,] 0.3417699 0.474303
Re: [R] Format printing with R
For better reproducibility, use dput to share data. A matrix and a data frame look similar, but they can act differently. On November 21, 2022 1:09:55 PM PST, Jim Lemon wrote: >Hi Steven, >I thought that the problem might be in the two large numbers, but >using a subset (I didn't want to edit out all the line numbers), I get >what I expected: > >sydf<-read.table(text="Mean Std.dev > [1,] 0.3107966 0.462820 > [2,] 0.1880302 0.390736 > [3,] 45.3185794 16.313635 > [4,] 0.5066370 0.499956 > [5,] 0.4933630 0.499956 > [6,] 0.7029150 0.456974 > [7,] 0.2970850 0.456974 > [8,] 0.7967066 0.402449 > [9,] 0.2032934 0.402449", >stringsAsFactors=FALSE,header=TRUE) >> print(sydf,digits=2) > Mean Std.dev >[1,] 0.310.46 >[2,] 0.190.39 >[3,] 45.32 16.31 >[4,] 0.510.50 >[5,] 0.490.50 >[6,] 0.700.46 >[7,] 0.300.46 >[8,] 0.800.40 >[9,] 0.200.40 > >I don't think it is your use of "cbind", but I didn't edit out Mean >and Std.dev and try it. > >Jim > >On Tue, Nov 22, 2022 at 7:41 AM Steven T. Yen via R-help > wrote: >> >> Hi, I have two variables with 86 observations each. Below I print with >> the print command with digit=2. But, I am getting three decimal places >> for my first variable and two for the second. Please help. Thanks. >> >> > cbind(Mean,Std.dev) >> Mean Std.dev >> [1,] 0.3107966 0.462820 >> [2,] 0.1880302 0.390736 >> [3,] 45.3185794 16.313635 >> [4,] 0.5066370 0.499956 >> [5,] 0.4933630 0.499956 >> [6,] 0.7029150 0.456974 >> [7,] 0.2970850 0.456974 >> [8,] 0.7967066 0.402449 >> [9,] 0.2032934 0.402449 >> [10,] 0.6582301 0.474303 >> [11,] 0.3417699 0.474303 >> [12,] 0.7262913 0.445861 >> [13,] 0.2737087 0.445861 >> [14,] 0.6415484 0.479546 >> [15,] 0.3584516 0.479546 >> [16,] 0.9110264 0.284706 >> [17,] 0.0889736 0.284706 >> [18,] 0.5211453 0.499553 >> [19,] 0.4788547 0.499553 >> [20,] 0.5481055 0.497680 >> [21,] 0.4518945 0.497680 >> [22,] 0.9135090 0.281088 >> [23,] 0.0864910 0.281088 >> [24,] 0.8727269 0.333279 >> [25,] 0.1272731 0.333279 >> [26,] 0.1015717 0.302084 >> [27,] 0.6043692 0.488986 >> [28,] 0.2940592 0.455619 >> [29,] 0.2735274 0.445769 >> [30,] 0.3777426 0.484823 >> [31,] 0.3487300 0.476568 >> [32,] 0.1603127 0.366896 >> [33,] 0.1723783 0.377709 >> [34,] 0.1230961 0.328547 >> [35,] 0.1779381 0.382461 >> [36,] 0.0964334 0.295185 >> [37,] 0.1584698 0.365181 >> [38,] 0.1113717 0.314592 >> [39,] 0.3349813 0.471984 >> [40,] 0.4081109 0.491484 >> [41,] 0.2569078 0.436928 >> [42,] 0.1034356 0.304527 >> [43,] 0.6741233 0.468701 >> [44,] 0.1254412 0.331218 >> [45,] 0.096 0.295958 >> [46,] 0.0587457 0.235148 >> [47,] 0.4401115 0.496400 >> [48,] 0.4689114 0.499033 >> [49,] 0.0322313 0.176614 >> [50,] 0.5907618 0.491693 >> [51,] 0.1591195 0.365787 >> [52,] 0.1132923 0.316950 >> [53,] 0.1124207 0.315883 >> [54,] 0.0244058 0.154305 >> [55,] 0.7058787 0.455647 >> [56,] 0.2941213 0.455647 >> [57,] 0.0746892 0.262889 >> [58,] 0.4749110 0.499370 >> [59,] 0.3471837 0.476075 >> [60,] 0.0435036 0.203988 >> [61,] 0.0597126 0.236954 >> [62,] 0.0478775 0.213507 >> [63,] 0.1152615 0.319337 >> [64,] 0.2074968 0.405514 >> [65,] 0.2440626 0.429530 >> [66,] 0.1605995 0.367161 >> [67,] 0.0804598 0.272004 >> [68,] 0.1442422 0.351335 >> [69,] 0.3443231 0.475147 >> [70,] 0.4280560 0.494797 >> [71,] 0.0528221 0.223678 >> [72,] 0.0805222 0.272100 >> [73,] 0.0457169 0.208870 >> [74,] 0.0485596 0.214945 >> [75,] 0.1333443 0.339946 >> [76,] 0.0932917 0.290841 >> [77,] 0.0653987 0.247228 >> [78,] 0.0573934 0.232593 >> [79,] 0.1399086 0.346892 >> [80,] 0.0887337 0.284359 >> [81,] 0.0984479 0.297919 >> [82,] 0.0914421 0.288237 >> [83,] 0.1155505 0.319685 >> [84,] 0.1363764 0.343188 >> [85,] 0.1134570 0.317151 >> [86,] 1.2985286 0.739096 >> > print(cbind(Mean,Std.dev),digits=2) >> Mean Std.dev >> [1,] 0.3110.46 >> [2,] 0.1880.39 >> [3,] 45.319 16.31 >> [4,] 0.5070.50 >> [5,] 0.4930.50 >> [6,] 0.7030.46 >> [7,] 0.2970.46 >> [8,] 0.7970.40 >> [9,] 0.2030.40 >> [10,] 0.6580.47 >> [11,] 0.3420.47 >> [12,] 0.7260.45 >> [13,] 0.2740.45 >> [14,] 0.6420.48 >> [15,] 0.3580.48 >> [16,] 0.9110.28 >> [17,] 0.0890.28 >> [18,] 0.5210.50 >> [19,] 0.4790.50 >> [20,] 0.5480.50 >> [21,] 0.4520.50 >> [22,] 0.9140.28 >> [23,] 0.0860.28 >> [24,] 0.8730.33 >> [25,] 0.1270.33 >> [26,] 0.1020.30 >> [27,] 0.6040.49 >> [28,] 0.2940.46 >> [29,] 0.2740.45 >> [30,] 0.3780.48 >> [31,] 0.3490.48 >> [32,] 0.1600.37 >> [33,] 0.1720.38 >> [34,] 0.1230.33 >> [35,] 0.1780.38 >> [36,] 0.0960.30 >> [37,] 0.1580.37 >> [38,] 0.1110.31 >> [39,] 0.3350.47 >> [40,] 0.4080.49 >> [41,] 0.257
Re: [R] Format printing with R
Hi Steven, I thought that the problem might be in the two large numbers, but using a subset (I didn't want to edit out all the line numbers), I get what I expected: sydf<-read.table(text="Mean Std.dev [1,] 0.3107966 0.462820 [2,] 0.1880302 0.390736 [3,] 45.3185794 16.313635 [4,] 0.5066370 0.499956 [5,] 0.4933630 0.499956 [6,] 0.7029150 0.456974 [7,] 0.2970850 0.456974 [8,] 0.7967066 0.402449 [9,] 0.2032934 0.402449", stringsAsFactors=FALSE,header=TRUE) > print(sydf,digits=2) Mean Std.dev [1,] 0.310.46 [2,] 0.190.39 [3,] 45.32 16.31 [4,] 0.510.50 [5,] 0.490.50 [6,] 0.700.46 [7,] 0.300.46 [8,] 0.800.40 [9,] 0.200.40 I don't think it is your use of "cbind", but I didn't edit out Mean and Std.dev and try it. Jim On Tue, Nov 22, 2022 at 7:41 AM Steven T. Yen via R-help wrote: > > Hi, I have two variables with 86 observations each. Below I print with > the print command with digit=2. But, I am getting three decimal places > for my first variable and two for the second. Please help. Thanks. > > > cbind(Mean,Std.dev) > Mean Std.dev > [1,] 0.3107966 0.462820 > [2,] 0.1880302 0.390736 > [3,] 45.3185794 16.313635 > [4,] 0.5066370 0.499956 > [5,] 0.4933630 0.499956 > [6,] 0.7029150 0.456974 > [7,] 0.2970850 0.456974 > [8,] 0.7967066 0.402449 > [9,] 0.2032934 0.402449 > [10,] 0.6582301 0.474303 > [11,] 0.3417699 0.474303 > [12,] 0.7262913 0.445861 > [13,] 0.2737087 0.445861 > [14,] 0.6415484 0.479546 > [15,] 0.3584516 0.479546 > [16,] 0.9110264 0.284706 > [17,] 0.0889736 0.284706 > [18,] 0.5211453 0.499553 > [19,] 0.4788547 0.499553 > [20,] 0.5481055 0.497680 > [21,] 0.4518945 0.497680 > [22,] 0.9135090 0.281088 > [23,] 0.0864910 0.281088 > [24,] 0.8727269 0.333279 > [25,] 0.1272731 0.333279 > [26,] 0.1015717 0.302084 > [27,] 0.6043692 0.488986 > [28,] 0.2940592 0.455619 > [29,] 0.2735274 0.445769 > [30,] 0.3777426 0.484823 > [31,] 0.3487300 0.476568 > [32,] 0.1603127 0.366896 > [33,] 0.1723783 0.377709 > [34,] 0.1230961 0.328547 > [35,] 0.1779381 0.382461 > [36,] 0.0964334 0.295185 > [37,] 0.1584698 0.365181 > [38,] 0.1113717 0.314592 > [39,] 0.3349813 0.471984 > [40,] 0.4081109 0.491484 > [41,] 0.2569078 0.436928 > [42,] 0.1034356 0.304527 > [43,] 0.6741233 0.468701 > [44,] 0.1254412 0.331218 > [45,] 0.096 0.295958 > [46,] 0.0587457 0.235148 > [47,] 0.4401115 0.496400 > [48,] 0.4689114 0.499033 > [49,] 0.0322313 0.176614 > [50,] 0.5907618 0.491693 > [51,] 0.1591195 0.365787 > [52,] 0.1132923 0.316950 > [53,] 0.1124207 0.315883 > [54,] 0.0244058 0.154305 > [55,] 0.7058787 0.455647 > [56,] 0.2941213 0.455647 > [57,] 0.0746892 0.262889 > [58,] 0.4749110 0.499370 > [59,] 0.3471837 0.476075 > [60,] 0.0435036 0.203988 > [61,] 0.0597126 0.236954 > [62,] 0.0478775 0.213507 > [63,] 0.1152615 0.319337 > [64,] 0.2074968 0.405514 > [65,] 0.2440626 0.429530 > [66,] 0.1605995 0.367161 > [67,] 0.0804598 0.272004 > [68,] 0.1442422 0.351335 > [69,] 0.3443231 0.475147 > [70,] 0.4280560 0.494797 > [71,] 0.0528221 0.223678 > [72,] 0.0805222 0.272100 > [73,] 0.0457169 0.208870 > [74,] 0.0485596 0.214945 > [75,] 0.1333443 0.339946 > [76,] 0.0932917 0.290841 > [77,] 0.0653987 0.247228 > [78,] 0.0573934 0.232593 > [79,] 0.1399086 0.346892 > [80,] 0.0887337 0.284359 > [81,] 0.0984479 0.297919 > [82,] 0.0914421 0.288237 > [83,] 0.1155505 0.319685 > [84,] 0.1363764 0.343188 > [85,] 0.1134570 0.317151 > [86,] 1.2985286 0.739096 > > print(cbind(Mean,Std.dev),digits=2) > Mean Std.dev > [1,] 0.3110.46 > [2,] 0.1880.39 > [3,] 45.319 16.31 > [4,] 0.5070.50 > [5,] 0.4930.50 > [6,] 0.7030.46 > [7,] 0.2970.46 > [8,] 0.7970.40 > [9,] 0.2030.40 > [10,] 0.6580.47 > [11,] 0.3420.47 > [12,] 0.7260.45 > [13,] 0.2740.45 > [14,] 0.6420.48 > [15,] 0.3580.48 > [16,] 0.9110.28 > [17,] 0.0890.28 > [18,] 0.5210.50 > [19,] 0.4790.50 > [20,] 0.5480.50 > [21,] 0.4520.50 > [22,] 0.9140.28 > [23,] 0.0860.28 > [24,] 0.8730.33 > [25,] 0.1270.33 > [26,] 0.1020.30 > [27,] 0.6040.49 > [28,] 0.2940.46 > [29,] 0.2740.45 > [30,] 0.3780.48 > [31,] 0.3490.48 > [32,] 0.1600.37 > [33,] 0.1720.38 > [34,] 0.1230.33 > [35,] 0.1780.38 > [36,] 0.0960.30 > [37,] 0.1580.37 > [38,] 0.1110.31 > [39,] 0.3350.47 > [40,] 0.4080.49 > [41,] 0.2570.44 > [42,] 0.1030.30 > [43,] 0.6740.47 > [44,] 0.1250.33 > [45,] 0.0970.30 > [46,] 0.0590.24 > [47,] 0.4400.50 > [48,] 0.4690.50 > [49,] 0.0320.18 > [50,] 0.5910.49 > [51,] 0.1590.37 > [52,] 0.1130.32 > [53,] 0.1120.32 > [54,] 0.0240.15 > [55,] 0.7060.46 > [56,] 0.2940.46
[R] Format printing with R
Hi, I have two variables with 86 observations each. Below I print with the print command with digit=2. But, I am getting three decimal places for my first variable and two for the second. Please help. Thanks. > cbind(Mean,Std.dev) Mean Std.dev [1,] 0.3107966 0.462820 [2,] 0.1880302 0.390736 [3,] 45.3185794 16.313635 [4,] 0.5066370 0.499956 [5,] 0.4933630 0.499956 [6,] 0.7029150 0.456974 [7,] 0.2970850 0.456974 [8,] 0.7967066 0.402449 [9,] 0.2032934 0.402449 [10,] 0.6582301 0.474303 [11,] 0.3417699 0.474303 [12,] 0.7262913 0.445861 [13,] 0.2737087 0.445861 [14,] 0.6415484 0.479546 [15,] 0.3584516 0.479546 [16,] 0.9110264 0.284706 [17,] 0.0889736 0.284706 [18,] 0.5211453 0.499553 [19,] 0.4788547 0.499553 [20,] 0.5481055 0.497680 [21,] 0.4518945 0.497680 [22,] 0.9135090 0.281088 [23,] 0.0864910 0.281088 [24,] 0.8727269 0.333279 [25,] 0.1272731 0.333279 [26,] 0.1015717 0.302084 [27,] 0.6043692 0.488986 [28,] 0.2940592 0.455619 [29,] 0.2735274 0.445769 [30,] 0.3777426 0.484823 [31,] 0.3487300 0.476568 [32,] 0.1603127 0.366896 [33,] 0.1723783 0.377709 [34,] 0.1230961 0.328547 [35,] 0.1779381 0.382461 [36,] 0.0964334 0.295185 [37,] 0.1584698 0.365181 [38,] 0.1113717 0.314592 [39,] 0.3349813 0.471984 [40,] 0.4081109 0.491484 [41,] 0.2569078 0.436928 [42,] 0.1034356 0.304527 [43,] 0.6741233 0.468701 [44,] 0.1254412 0.331218 [45,] 0.096 0.295958 [46,] 0.0587457 0.235148 [47,] 0.4401115 0.496400 [48,] 0.4689114 0.499033 [49,] 0.0322313 0.176614 [50,] 0.5907618 0.491693 [51,] 0.1591195 0.365787 [52,] 0.1132923 0.316950 [53,] 0.1124207 0.315883 [54,] 0.0244058 0.154305 [55,] 0.7058787 0.455647 [56,] 0.2941213 0.455647 [57,] 0.0746892 0.262889 [58,] 0.4749110 0.499370 [59,] 0.3471837 0.476075 [60,] 0.0435036 0.203988 [61,] 0.0597126 0.236954 [62,] 0.0478775 0.213507 [63,] 0.1152615 0.319337 [64,] 0.2074968 0.405514 [65,] 0.2440626 0.429530 [66,] 0.1605995 0.367161 [67,] 0.0804598 0.272004 [68,] 0.1442422 0.351335 [69,] 0.3443231 0.475147 [70,] 0.4280560 0.494797 [71,] 0.0528221 0.223678 [72,] 0.0805222 0.272100 [73,] 0.0457169 0.208870 [74,] 0.0485596 0.214945 [75,] 0.1333443 0.339946 [76,] 0.0932917 0.290841 [77,] 0.0653987 0.247228 [78,] 0.0573934 0.232593 [79,] 0.1399086 0.346892 [80,] 0.0887337 0.284359 [81,] 0.0984479 0.297919 [82,] 0.0914421 0.288237 [83,] 0.1155505 0.319685 [84,] 0.1363764 0.343188 [85,] 0.1134570 0.317151 [86,] 1.2985286 0.739096 > print(cbind(Mean,Std.dev),digits=2) Mean Std.dev [1,] 0.311 0.46 [2,] 0.188 0.39 [3,] 45.319 16.31 [4,] 0.507 0.50 [5,] 0.493 0.50 [6,] 0.703 0.46 [7,] 0.297 0.46 [8,] 0.797 0.40 [9,] 0.203 0.40 [10,] 0.658 0.47 [11,] 0.342 0.47 [12,] 0.726 0.45 [13,] 0.274 0.45 [14,] 0.642 0.48 [15,] 0.358 0.48 [16,] 0.911 0.28 [17,] 0.089 0.28 [18,] 0.521 0.50 [19,] 0.479 0.50 [20,] 0.548 0.50 [21,] 0.452 0.50 [22,] 0.914 0.28 [23,] 0.086 0.28 [24,] 0.873 0.33 [25,] 0.127 0.33 [26,] 0.102 0.30 [27,] 0.604 0.49 [28,] 0.294 0.46 [29,] 0.274 0.45 [30,] 0.378 0.48 [31,] 0.349 0.48 [32,] 0.160 0.37 [33,] 0.172 0.38 [34,] 0.123 0.33 [35,] 0.178 0.38 [36,] 0.096 0.30 [37,] 0.158 0.37 [38,] 0.111 0.31 [39,] 0.335 0.47 [40,] 0.408 0.49 [41,] 0.257 0.44 [42,] 0.103 0.30 [43,] 0.674 0.47 [44,] 0.125 0.33 [45,] 0.097 0.30 [46,] 0.059 0.24 [47,] 0.440 0.50 [48,] 0.469 0.50 [49,] 0.032 0.18 [50,] 0.591 0.49 [51,] 0.159 0.37 [52,] 0.113 0.32 [53,] 0.112 0.32 [54,] 0.024 0.15 [55,] 0.706 0.46 [56,] 0.294 0.46 [57,] 0.075 0.26 [58,] 0.475 0.50 [59,] 0.347 0.48 [60,] 0.044 0.20 [61,] 0.060 0.24 [62,] 0.048 0.21 [63,] 0.115 0.32 [64,] 0.207 0.41 [65,] 0.244 0.43 [66,] 0.161 0.37 [67,] 0.080 0.27 [68,] 0.144 0.35 [69,] 0.344 0.48 [70,] 0.428 0.49 [71,] 0.053 0.22 [72,] 0.081 0.27 [73,] 0.046 0.21 [74,] 0.049 0.21 [75,] 0.133 0.34 [76,] 0.093 0.29 [77,] 0.065 0.25 [78,] 0.057 0.23 [79,] 0.140 0.35 [80,] 0.089 0.28 [81,] 0.098 0.30 [82,] 0.091 0.29 [83,] 0.116 0.32 [84,] 0.136 0.34 [85,] 0.113 0.32 [86,] 1.299 0.74 > __ R-help@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.