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

How to "skip" or leave a blank in ifelse function?

I made a program that stores negative values from deviates of a normal distribution using ifelse():

n <- 100000
z <- rnorm(n)
ifelse(z<0,z,___)

However, I want the function to work so that if the deviate is positive, the function would skip that value and proceed to the next one (I don’t want to put "NA" in the no argument of the ifelse function). Is there any argument I can put in the ___ to get what I need? Thank you!

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 :

An option could be:

n <- 100000
z <- rnorm(n)


if(z < 0) {
  print(z)
}
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