First, a little background on the meaning of a p value
The p value in a t-test (any t-test, not just two independent samples) refers to what proportion of t-statistics (for those degrees of freedom) are that extreme or more, assuming you want a two-tailed p value. If you want a one-tailed p value, then it's what proportion of t-statistics (for those degrees of freedom) are that high or higher (for the positive tail) or that low or lower (for the negative tail).
There is a defined theoretical distribution of t-statistics (the t distribution). So as long as you know how many degrees of freedom you have, you know theoretically what distribution your t-statistic came from under the null hypothesis. That mens you can compare that t-statistic to the rest of its null distribution --- if it's a very unusual value for that distribution (i.e. way out in one of the tails), the you conclude that it is unlikely to have come from the null distribution. The p value is simply the proportion of the distribution --- the area under the curve --- that is at least as far from 0 as your t-statistic.
How p values are calculated
So in order to calculate the p value that corresponds to a particular t-statistic at some degrees of freedom, you need to measure the area under the curve from that point on out. Since the distribution is symmetrical, you can simply double that value to get the two-tailed p-value. If you've taken calculus, you may already know what needs to be done: The area under a curve is the integral of the function that defines the curve. Here's the function that defines the t-distribution (its probability density function, or PDF):
where nu (looks sort of like a "v") is the number of degrees of freedom and Gamma (looks sort of like an upside down "L") is the gamma function.
In your example, your t statistic is 0.6595. You want to get the area under the curve from 0.6595 up, i.e. from 0.6595 to positive infinity. You would enter these as the values over which to integrate, and then crunch through the calculus to evaluate the integral of the t PDF function. This gives you the area under the curve from 0.6595 up, but for a two-tailed test you also want it from -0.6595 down. Since the distribution is symmetrical, you don't have to separately calculate that --- it will be exactly the same, so you can just double the value you got from 0.6595 to positive infinity.
That's a lot of intense calculation for what is otherwise a pretty simple test; most of us casual t-test users are not up for that kind of time investment. Instead, we have historically printed out tables of already-calculated p values for a range of degrees of freedom and t-statistics (you are likely to find such a table in the back of your intro to stats text book), or included algorithms in our software that do the heavy lifting of the p value calculation for us, as is suggested by the p()
function in your question. That function represents the area under the curve of the t-statistic PDF for greater than or equal to your observed t-statistic. In R, that function is pt()
.