I've created a short program to print a table of learning curve factors. However, I cannot figure out how to format the table to: 1) Get rid of the [1]s in the first column and replace it with the values of N. 2) Line up the first row with the factors (decimal fractions). Thanks for any help. The complete program and output is as follows:> Lc<-seq(0.70,0.95,0.05) #Specify learning curves > T<-function(N,Lc) #Create a function to calc.time for Nth unit+ { + N^(log(Lc,10)/log(2,10)) #Function + }> for (N in seq(2,10,2))+ {if (N==2){print(T(N,Lc)*100)}else{print(T(N,Lc),digits=3)}} [1] 70 75 80 85 90 95 [1] 0.490 0.562 0.640 0.722 0.810 0.902 [1] 0.398 0.475 0.562 0.657 0.762 0.876 [1] 0.343 0.422 0.512 0.614 0.729 0.857 [1] 0.306 0.385 0.477 0.583 0.705 0.843>-- View this message in context: http://www.nabble.com/Formatting-a-Table-tp24391433p24391433.html Sent from the R help mailing list archive at Nabble.com.
You could use 'cat(sprintf())', C-style:> for (N in seq(2,10,2))+ {if (N==2){cat(sprintf("%5d", T(N,Lc)*100),"\n")}else{cat(sprintf("%5.3f", T(N,Lc)), "\n")}} 70 75 80 85 89 95 0.490 0.562 0.640 0.722 0.810 0.902 0.398 0.475 0.562 0.657 0.762 0.876 0.343 0.422 0.512 0.614 0.729 0.857 0.306 0.385 0.477 0.583 0.705 0.843 On Wed, Jul 8, 2009 at 9:20 AM, cvandy<cvandy26 at gmail.com> wrote:> > I've created a short program to print a table of learning curve factors. > However, I cannot figure out how to format the table to: > 1) Get rid of the [1]s in the first column and replace it with the values of > N. > 2) Line up the first row with the factors (decimal fractions). > Thanks for any help. > The complete program and output is as follows: > >> Lc<-seq(0.70,0.95,0.05) #Specify learning curves >> T<-function(N,Lc) ?#Create a function to calc.time for Nth unit > + { > + N^(log(Lc,10)/log(2,10)) ?#Function > + } >> for (N in seq(2,10,2)) > + {if (N==2){print(T(N,Lc)*100)}else{print(T(N,Lc),digits=3)}} > [1] 70 75 80 85 90 95 > [1] 0.490 0.562 0.640 0.722 0.810 0.902 > [1] 0.398 0.475 0.562 0.657 0.762 0.876 > [1] 0.343 0.422 0.512 0.614 0.729 0.857 > [1] 0.306 0.385 0.477 0.583 0.705 0.843 >> > -- > View this message in context: http://www.nabble.com/Formatting-a-Table-tp24391433p24391433.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. >
Cvandy, is this close to what you need:
> printT <- function ( .seq = seq ( 2 , 10 , 2 ) ) {
+ x <- t ( sapply ( .seq , T , Lc ) )
+ x <- cbind (
+ .seq
+ , rbind (
+ format ( x [ 1 , ] * 100 )
+ , format ( x [ -1 , ] , digits = 3 )
+ )
+ )
+ dimnames ( x ) [[2]] <- NULL
+ print ( x , quote = FALSE )
+ }
> printT ( )
[,1] [,2] [,3] [,4] [,5] [,6] [,7]
[1,] 2 70 75 80 85 90 95
[2,] 4 0.490 0.562 0.640 0.722 0.810 0.902
[3,] 6 0.398 0.475 0.562 0.657 0.762 0.876
[4,] 8 0.343 0.422 0.512 0.614 0.729 0.857
[5,] 10 0.306 0.385 0.477 0.583 0.705 0.843
Im not really sure what you mean by "Line up the first row with
the factors (decimal fractions)".
--
David
?
-----------------------------------------------------
David Huffer, Ph.D. Senior Statistician
CSOSA/Washington, DC david.huffer at csosa.gov
-----------------------------------------------------
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of cvandy
Sent: Wednesday, July 08, 2009 9:21 AM
To: r-help at r-project.org
Subject: [R] Formatting a Table
I've created a short program to print a table of learning curve factors.
However, I cannot figure out how to format the table to:
1) Get rid of the [1]s in the first column and replace it with the values of
N.
2) Line up the first row with the factors (decimal fractions).
Thanks for any help.
The complete program and output is as follows:
> Lc<-seq(0.70,0.95,0.05) #Specify learning curves
> T<-function(N,Lc) #Create a function to calc.time for Nth unit
+ {
+ N^(log(Lc,10)/log(2,10)) #Function
+ }> for (N in seq(2,10,2))
+ {if (N==2){print(T(N,Lc)*100)}else{print(T(N,Lc),digits=3)}}
[1] 70 75 80 85 90 95
[1] 0.490 0.562 0.640 0.722 0.810 0.902
[1] 0.398 0.475 0.562 0.657 0.762 0.876
[1] 0.343 0.422 0.512 0.614 0.729 0.857
[1] 0.306 0.385 0.477 0.583 0.705 0.843>
--
View this message in context:
http://www.nabble.com/Formatting-a-Table-tp24391433p24391433.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.