library(ggplot2)
# p is going to be the vector of hypothetical values that go from 0 to 1 in increments of 0.01.
p=seq(from=0,to=1,by=0.01)
# vectorized operations note we did not have to declare
# the likelihood vector. The arithmetic function will be evaluated for each element
Likelihood=p^3*(1-p)^3
#Find the index likelihood is maximized.
which.max(Likelihood)
[1] 51
[1] 0.015625
[1] 0.5