Hello there!
Trying to drive command where i would get values from X which are between variables y and z. I didn't find it from my R quide, does anyone remember?
Assuming X,y and z are all numeric values in the same dataframe and you mean to include X == y & X == z
suppressPackageStartupMessages({
library(dplyr)
})
mtcars %>% select(mpg, wt, qsec) %>%
filter(mpg <= wt*10 & mpg <= qsec)
#> mpg wt qsec
#> Valiant 18.1 3.460 20.22
#> Duster 360 14.3 3.570 15.84
#> Merc 230 22.8 3.150 22.90
#> Merc 280C 17.8 3.440 18.90
#> Merc 450SE 16.4 4.070 17.40
#> Merc 450SL 17.3 3.730 17.60
#> Merc 450SLC 15.2 3.780 18.00
#> Cadillac Fleetwood 10.4 5.250 17.98
#> Lincoln Continental 10.4 5.424 17.82
#> Chrysler Imperial 14.7 5.345 17.42
#> Dodge Challenger 15.5 3.520 16.87
#> AMC Javelin 15.2 3.435 17.30
#> Camaro Z28 13.3 3.840 15.41
Created on 2020-11-28 by the reprex package (v0.3.0.9001)
Next time, provide a reprex
Hi, y and z are numeric values and X is numeric vector. Funktion should return values from X which are between y and z.
So you are satisfied with technocrats solution?
I think I should use x(min=y, max=z)
Why do you think that?
Beacause I have to have those values from X which are between y and z.
vecbetween <- function(val,left,right){
val[ val >= left & val <= right ]
}
> vecbetween(1:10,5,7)
[1] 5 6 7
I've also worked with that one. Still my propblem is making subvector from those values and return it with my function.