Given a plot of N against P, I'm trying to find out what is the value of P, when N is 386 in R?

My data is obtained using this code in R:

N <- seq(from=100,to=2000,by=1)
P <- choose(N-100, 50) / choose(N, 60)
## Normalization of Ps:
P <- P / sum(P)
## Plot it:
plot(N, P, type = "l",las=1)

I'm using the following code with no success:

P[which(N) = 386]
  • $\begingroup$ In your data P ranges from 0 to 0.002; so no P is equal to 386. $\endgroup$
    – discipulus
    Nov 27, 2016 at 2:08
  • $\begingroup$ Oh No, I'm asking WHAT IS P? when N is 386! N goes from 100 to 2000!! $\endgroup$ Nov 27, 2016 at 2:11
  • $\begingroup$ See updated answer below: P[which(N == 386)] $\endgroup$
    – discipulus
    Nov 27, 2016 at 2:18
  • $\begingroup$ Purely programming-issue questions are off topic here; given you've had multiple questions closed over this issue, I can only presume you must know this already. I would migrate this to stackoverflow but you're blocked from asking on SO. Don't post to another site (i.e. here) as a way of avoiding a block on the site where the question belongs -- resolve the issue that led to being blocked at the original site. $\endgroup$
    – Glen_b
    Nov 27, 2016 at 2:46

1 Answer 1


You were close, remember which() takes logical operator (i.e., ==), you have provided = which is an assignment operator. If you have the plot, you must have data that generated it. Since you have not provided the data. I have created one myself.

# Set seed for reproducible example 

# Create a dataframe of random numbers 
mydf <- data.frame(X=rnorm(45),Y=rnorm(45))

# For example set the value of 5th element to 386 as in your question
mydf$X[5] <- 386

# Print the fifth value of Y

# Use to find X where it is value and print equivalent value of Y

Update: With the newer set of data and questions you have provided:: Change the final statement to simply::

 P[which(N == 386)]
  • $\begingroup$ discipulus thank you here is my data: 386 was just an example not related to my data. I will want the answer to be used in creating arrows. N <- seq(from=100,to=2000,by=1) P <- choose(N-100, 50) / choose(N, 60) ## Normalization of Ps to make the total area under the curve become 1: sum(P) P <- P / sum(P) #P <- P / max(P) ## Plot it: plot(N, P, type = "l",las=1) $\endgroup$ Nov 27, 2016 at 1:53
  • $\begingroup$ Could you please update the question with data, not with a comment here? $\endgroup$
    – discipulus
    Nov 27, 2016 at 1:56
  • $\begingroup$ sure, right away $\endgroup$ Nov 27, 2016 at 1:56
  • $\begingroup$ I tweaked your 1st sentence to make your point clearer (+1), but I think I on the boundary of what is acceptable editing here. See if you're OK w/ it, & if not, roll it back w/ my apologies. $\endgroup$ Nov 27, 2016 at 2:14
  • $\begingroup$ Thanks very much I was a = short of getting it, thanks a lot! $\endgroup$ Nov 27, 2016 at 2:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.