-5

I have a vector containing the minimum and maximum of 3 ranges i.e

low<-1,2,3
high<-2,3,4

represent the ranges 1-2,2-3,and 3-4

I need to return a third vector containing the midpoint of each range i.e.

mid<-1.5,2.5,3.5

Any quick way to do this?

Elizabeth
  • 5,771
  • 16
  • 57
  • 88
  • 2
    You are mixing median and midpoint in your question. They are not the same thing. From your example it looks like it's the midpoint that you are after and not the median. – Jens Agby Aug 25 '12 at 09:16
  • The median and midpoint for a series of only 2 numbers would be the same number though.... – Elizabeth Aug 25 '12 at 13:03
  • Yes, you are correct. If you have a set of only two numbers they are indeed the same value. But I would still not use them interchangeably since they mean different things. This is a special case where they happen to be the same value. – Jens Agby Aug 25 '12 at 17:45

1 Answers1

5

Assuming you've actually got low <- c(1, 2, 3) etc, then:

mid <- (low + high)/2
seancarmody
  • 5,890
  • 1
  • 31
  • 30