Hello R users, I am writing a summary() for a custom class, and am to display the integers right justified, Say where x is the vector with integers, I am using the following: cat("\t",format(x),"\t"...other columns) this way I am trying to pass the format(x), to the cat function to display it, but still I am getting a kink(b/w the 9th and 10th row). 6 81 170 251 1.998026e-08 7 26 93 119 4.937587e-10 8 96 209 305 8.750939e-11 9 94 211 305 1.758285e-11 10 88 205 293 6.47853e-12 11 82 244 326 7.943691e-20 12 57 145 202 4.964509e-10 Thanks, -- Regards, Sahil Seth JHSPH [[alternative HTML version deleted]]
try using 'sprintf' On Fri, Oct 9, 2009 at 8:36 AM, sahil seth <sahiilseth at gmail.com> wrote:> Hello R users, > I am writing a summary() for a custom class, and am to display the integers > right justified, > Say where x is the vector with integers, I am using the following: > cat("\t",format(x),"\t"...other columns) > > this way I am trying to pass the format(x), to the cat function to display > it, > but still I am getting a kink(b/w the 9th and 10th row). > ? 6 ? ? ?81 ? ? ?170 ? ? ?251 ? ? ?1.998026e-08 > ? 7 ? ? ?26 ? ? ?93 ? ? ?119 ? ? ?4.937587e-10 > ? 8 ? ? ?96 ? ? ?209 ? ? ?305 ? ? ?8.750939e-11 > ? 9 ? ? ?94 ? ? ?211 ? ? ?305 ? ? ?1.758285e-11 > ? ? 10 ? ? ?88 ? ? ?205 ? ? ?293 ? ? ?6.47853e-12 > ? ? 11 ? ? ?82 ? ? ?244 ? ? ?326 ? ? ?7.943691e-20 > ? ? 12 ? ? ?57 ? ? ?145 ? ? ?202 ? ? ?4.964509e-10 > Thanks, > -- > Regards, > Sahil Seth > JHSPH > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
On 10/09/2009 11:36 PM, sahil seth wrote:> Hello R users, > I am writing a summary() for a custom class, and am to display the integers > right justified, > Say where x is the vector with integers, I am using the following: > cat("\t",format(x),"\t"...other columns) > > this way I am trying to pass the format(x), to the cat function to display > it, > but still I am getting a kink(b/w the 9th and 10th row). > 6 81 170 251 1.998026e-08 > 7 26 93 119 4.937587e-10 > 8 96 209 305 8.750939e-11 > 9 94 211 305 1.758285e-11 > 10 88 205 293 6.47853e-12 > 11 82 244 326 7.943691e-20 > 12 57 145 202 4.964509e-10 > Thanks, >HI Sahil, The "kink" is due to the fact that each row is being formatted separately. You may notice that there is a kink in row 7 as well, due to the same problem. What you may want to do is use formatC instead of format like this: cat(formatC(x,width=10),...,rep(" ",6),<last number>,"\n",sep="") Jim