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

Find a vector given certain criteria in R

I was searching online if it is possible to create a vector given certain conditions, such as it must contain 2 and 6 but not 5 and 1, also that it is in a specific range (2 000 000-4 999 999), and also that it must be even.
I have genuinely no idea about how to give these commands to R even if I know the basic functions to create a vector.

Thanks in advance for your time and for the big 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 :

You can create it using "seq" function.

seq(from = 2, to = 7, by = 2) 
#> [1] 2 4 6

Then use "setdiff" function to remove specific values you dont need.

remove <- c(2)

#> a
 [1] 2 4 6
#> setdiff(a, remove)
[1] 4 6
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