-1

I want to calculate the correlation between sf and pf only for values correspond to half of (highest values) P

  P=c(1,6,5,6,2,8,5)
  sf=c(1,2,6,6,4,5,5)
  Pf=c(1,6,5,8,4,8,5)
  cor(sf,Pf)

Any help please?

hyat
  • 1,047
  • 4
  • 15
  • 34
  • Looks like trivial problem. See question https://stackoverflow.com/questions/6760284/how-to-calculate-correlation-in-r?rq=1 – Doc Jun 25 '17 at 19:05

1 Answers1

4

If I understand you correctly, then this should do the trick

cor(sf[P > median(P)], Pf[P > median(P)])

Since you want the top 50% of P, this corresponds to the values of P greater than the median.

csgillespie
  • 59,189
  • 14
  • 150
  • 185