Procházet zdrojové kódy

Adding flag to modify number of decimal places in get.mean

Andrej před 2 dny
rodič
revize
ceed40896b
2 změnil soubory, kde provedl 11 přidání a 3 odebrání
  1. 8 2
      R/stats.R
  2. 3 1
      man/get.mean.Rd

+ 8 - 2
R/stats.R

@@ -1,13 +1,19 @@
 #' Construct a string to report mean and SD
 
 #' @param v a vector of values
+#' @param nD number of decimals to print
 #'
 #' @return a combined string
 #'
 #' @export
 
-get.mean<-function(v){
-   base::sprintf('%.0f (%.0f)',base::mean(v,na.rm=TRUE),stats::sd(v,na.rm=TRUE))
+get.mean<-function(v,nD=0){
+   if (nD==2){
+      x=base::sprintf('%.2f (%.2f)',base::mean(v,na.rm=TRUE),stats::sd(v,na.rm=TRUE))
+   } else {
+      x=base::sprintf('%.0f (%.0f)',base::mean(v,na.rm=TRUE),stats::sd(v,na.rm=TRUE))
+   }
+   x
 }
 
 #' Construct a string to report median and range

+ 3 - 1
man/get.mean.Rd

@@ -4,10 +4,12 @@
 \alias{get.mean}
 \title{Construct a string to report mean and SD}
 \usage{
-get.mean(v)
+get.mean(v, nD = 0)
 }
 \arguments{
 \item{v}{a vector of values}
+
+\item{nD}{number of decimals to print}
 }
 \value{
 a combined string