-1

Let x be the vector for the height of fathers

x <- c(180.3, 177.4, etc) 

and y be the height of the corresponding sons

y <- c(179.5, 178.5, etc)

I now want to create a subset of fathers whose height is within 2.5cm of x=182 with the corresponding sons. How do I do this?

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
Chance Gordon
  • 143
  • 1
  • 8
  • 2
    Did you try anything? Where exactly did you get suck? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Including parts like "etc" isn't very useful since that's not reproducible. – MrFlick Jan 24 '20 at 20:17
  • Does this answer your question? [How do I filter a range of numbers in R?](https://stackoverflow.com/questions/51107901/how-do-i-filter-a-range-of-numbers-in-r) – camille Jan 24 '20 at 20:49

1 Answers1

1

We can create a logical vector to subset the 'x'

i1 <- x >= (182 - 2.5) & x < (182 + 2.5)
x1 <- x[i1]
y1 <- y[i1]
akrun
  • 874,273
  • 37
  • 540
  • 662