Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R Combining and creating functions

Here’s my code

mean <- 100
sd <- 15
Fluorescence_Intensity = rnorm(x, mean, sd)

I would like to create a function that calculates Fluorescence Intensity for me where I can give and change the value of sd mean and distribution for example rnorm to dnorm.
As I am new to both R as in this forum, please help

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This should do the job:

Fluorescence_Intensity <- function(X, MEAN, SD, METHOD){
  if(METHOD=="rnorm"){
    res <- rnorm(X, MEAN, SD)
  }
  if(METHOD=="dnorm"){
    res <- dnorm(X, MEAN, SD)
  }
  print(res)
}

Fluorescence_Intensity(X=10, MEAN=100, SD=7, METHOD="rnorm")
Fluorescence_Intensity(X=10, MEAN=100, SD=7, METHOD="dnorm")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading