[R-sig-teaching] Fwd: Normal Distribution Table

Steven Stoline sstoline at gmail.com
Sat Feb 21 11:49:17 CET 2015


One more thing;

3- how to force all output to be in a 4 decimal format. e.g. 1 should look
like 1.0000.

thanks
steve
---------- Forwarded message ----------
From: Steven Stoline <sstoline at gmail.com>
Date: Sat, Feb 21, 2015 at 5:37 AM
Subject: Normal Distribution Table
To: R-sig-teaching <R-sig-teaching at r-project.org>


Dear All:

I am trying to use the below R code to create the standard normal
distribution table. But I need some helps on the output:

1- how I can insert one line-space between each two rows.

2- there is  one "<NA>" in the output, how to remove it from the output.

Simply copy-paste the below code into R.


Here is the Code:
============


columnz<-c(0.00, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09)


rowz<-c(0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,

2.0,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.1,3.2,3.3,3.4,3.5,3.6,3.7,3.8,3.9,4.0)


normal.table<-function(columnz,rowz){


m<-length(rowz)

n<-length(columnz)


A<-matrix(NA, nrow = m+1 , ncol = n+1)


for (i in (1:m+1)) {

    A[i,1]<-"   "

}


for (j in (1:n+1)) {

    A[1,j]<-"------"

}


for (i in (1:m)) {
  for (j in (1:n)){

####    A[i,j]<-round(pnorm(rowz[i]+columnz[j]),4)

   A[i+1,j+1]<-round(pnorm(rowz[i]+columnz[j]),4)


  }

}



 dimnames(A)<-list(c("  ",
"0.0","0.1","0.2","0.3","0.4","0.5","0.6","0.7","0.8","0.9",

"1.0","1.1","1.2","1.3","1.4","1.5","1.6","1.7","1.8","1.9",

"2.0","2.1","2.2","2.3","2.4","2.5","2.6","2.7","2.8","2.9",

"3.0","3.1","3.2","3.3","3.4","3.5","3.6","3.7","3.8","3.9","4.0"),
                    c("  ", " 0.00", " 0.01", " 0.02", " 0.03", " 0.04", "
0.05", " 0.06", " 0.07", " 0.08", " 0.09"))

 print(A,quote=F)

 invisible()

}

normal.table(columnz,rowz)


with many thanks
Steve

-- 
Steven M. Stoline
1123 Forest Avenue
Portland, ME 04112
sstoline at gmail.com



-- 
Steven M. Stoline
1123 Forest Avenue
Portland, ME 04112
sstoline at gmail.com

	[[alternative HTML version deleted]]



More information about the R-sig-teaching mailing list