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

Comparisons of more than two lists in R

For my problem, I have 4 lists, each containing 10,000 elements. Let the lists be a, b, c, d. I can calculate Probablity(a<b) by just performing mean operation mean(a<b). If I understand correctly, it compares each of the 10,000 elements in a and b in order and tells me for how many elements a<b holds (with the number being divided by total elements).

Now, I want to compute Probablity(a<b<c<d). I want r to compare 10,000 elements in order and tell me for how many elements does (a<b<c<d) hold. However, I’m unable to do it using the mean function since it doesn’t accept more than one < sign. How can I use the mean function here? I’m an absolute beginner in r, but logically, I feel this should be straightforward rather than looping over everything and having a count variable.

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 :

How about this:

a <- runif(10000)
b <- runif(10000)
c <- runif(10000)
d <- runif(10000)
mean(a<b & b<c & c<d)
#> [1] 0.0425

Created on 2022-12-06 by the reprex package (v2.0.1)

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