From 6014483d1cd4382f57ffe008283b1f3d0f27ad08 Mon Sep 17 00:00:00 2001 From: Waldir Leoncio Date: Tue, 17 Dec 2019 15:34:47 +0100 Subject: [PATCH] Added rand function --- NAMESPACE | 1 + R/rand.R | 9 +++++++++ man/rand.Rd | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 R/rand.R create mode 100644 man/rand.Rd diff --git a/NAMESPACE b/NAMESPACE index 4b0f262..55f7c5f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,3 +6,4 @@ export(computeRows) export(learn_simple_partition) export(ownNum2Str) export(repmat) +importFrom(stats,runif) diff --git a/R/rand.R b/R/rand.R new file mode 100644 index 0000000..9e23039 --- /dev/null +++ b/R/rand.R @@ -0,0 +1,9 @@ +#' @title Generate matrix with U(0, 1) trials +#' @description Imitates the behavior of `rand()` on Matlab +#' @param r number of rows of output matrix +#' @param c number of columns of output matrix +#' @return \eqn{r \times c} matrix with random trials from a standard uniform distribution. +#' @importFrom stats runif +rand <- function(r = 1, c = 1) { + matrix(runif(r * c), r, c) +} \ No newline at end of file diff --git a/man/rand.Rd b/man/rand.Rd new file mode 100644 index 0000000..131a43c --- /dev/null +++ b/man/rand.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/rand.R +\name{rand} +\alias{rand} +\title{Generate matrix with U(0, 1) trials} +\usage{ +rand(r = 1, c = 1) +} +\arguments{ +\item{r}{number of rows of output matrix} + +\item{c}{number of columns of output matrix} +} +\value{ +\eqn{r \times c} matrix with random trials from a standard uniform distribution. +} +\description{ +Imitates the behavior of `rand()` on Matlab +}