Reputation: 7517
I've written a simple function in R (see below) which works well. But, I get an unwanted word: "Null" at the end of the output when I execute the code.
I was wondering how I could modify my current code to remove the the unwanted, extra word "Null" that appears at the end of the output given by this function?
Here is my R code:
postsigma <- function(n,sigma2,b2,mu,mean){
SigPost <- (1/((n/sigma2)+(1/b2)))
MuPost <- ((SigPost/b2)*mu)+((SigPost/(sigma2/n))*mean)
curve(dnorm(x,MuPost,sqrt(SigPost)),xlim=c(0,MuPost+4),ylim=c(0,dnorm(MuPost,MuPost,sqrt(SigPost))+.02),ylab="Density",main=expression("Posterior of "(mu)))
D <- cat("\t","Mu of Posterior:","\t",MuPost,"\n","\t","Sigma of Posterior:",SigPost)
return(D)}
postsigma(200,15,5,2,5)
Upvotes: 1
Views: 97
Reputation: 37641
The NULL is the value of D. R will print this out. Just remove the statement return(D)
and it will get rid of the NULL. You might also want to add a linefeed \n
to your cat
statement
Also there is no reason to save the result of the cat
in D. You can leave off D <-
as well.
Upvotes: 3