I would like to know about below questions.
How many years of historical data is require for Portfolio Optimization in R programming.
Speaking about portfolio optimization in general, historical data is required to estimate the variance-covariance matrix that gives you the volatilities of the stock returns and the covariances thereof. The estimation depends on the periodicity of your returns, i.e. whether you are using intraday, daily, weekly, or monthly returns. (For intraday/daily returns you would also need a noise adjustment.)
Theoretically, you can use any length of time series to estimate the matrix. The more data you use to estimate the matrix the more robust it will be. But the correlation relationship between the returns may change over time so it can be feasible to not use all available data. The required time series length also depends on the mentioned periodicity of your returns. For daily returns one year (250 trading days) may be enough, for monthly returns one year may be too few.
I agree with everything dnl said. This time period choice can get very involved. You are explicitly choosing an historical period that you think will be repeated in the future. Unfortunately, history does not repeat exactly. There is an old saying, all models are wrong, but some are useful. There is no right answer for the period. Should you include just a recent past or include periods of sharp market moves? Additionally, there are those that just over-ride the correlation matrix and returns numbers because they explicitly believe they can forecast better than using a previous period. You might want to explore the Black-Litterman model to see how some try to improve on the efficient frontier model. If I were doing this, I might look at the correlations estimated only during a rising interest rate environment.