NPV estimation 
////////////////////////////
Definition of NPV (Net Present Value)

Method I: NPV = PV(all benefits) - pv(all costs)

Method II: if cash outflow is defined as a negative value
              cash inflow  is defined as a positive value
           NPV = PV(all cash flows)

  NPV Rule: for an independent project
        if NPV(Project) > 0 accept
        if NPV(Project) < 0 reject
Assume that we have the following investment opportunity. 
What is NPV if the discount rate is 0.05?
0,-100
1,20
2,30
3,40
4,50
5,20

a) use Excel 
b) use pv_f<-function(fv,r,n)fv/(1+r)**n

////////////////////////////////

customize x-axis 
////////////////////////////////
# Sample data

set.seed(123)
n <- 1:100
y <- rnorm(100)

# Plot with log(n) on x-axis
plot(log(n), y, xaxt = "n", xlab = "n", ylab = "y")

# Customize x-axis to show n values
axis(1, at = log(n), labels = n)
///////////////////////////////

select()
///////////////////////

library(dplyr)
x <- data.frame(
Name = c("Orange", "Apple", "Lemon", "Banana", "Grapefruit"),
Type = c("Citrus", "Pome", "Citrus", "Berry", "Citrus"),
  Price = c(1.00, 1.50, 0.75, 0.50, 1.25),
  Quantity = c(10, 20, 15, 30, 12)
)

selected_columns <- x %>%
   select(Name, Price)
print(selected_columns)


///////////////////////

paste() vs. paste0() functions 
////////////////////////////
The paste() function can be used to put two string together. 

   a<-'I love'
   b<-'dogs'
   paste(a,b)

If we don't want a space between. 
  paste(a,b,sep='')

  paste(a,b,sep=',')

  paste0(a,b)  => paste(a,b,sep='')
/////////////////////////

.niceFormula() function 
////////////////////////////////
Just type .niceFormula

Objective: generate a set of nice (Latex) formulas

 Example #1:> .niceFormula      # see this help
 
 Example #2:> .nf               # a short-cut
 
 Example #3:> .nf()
           * ------------------------------------------------------------- *
           * Objective: Present a formula nicely (Latex format)            *
           *            you need an R package called 'latex2exp'           *
           *            install.packages('latex2exp')                      *
           * ------------------------------------------------------------- *
         1     fv(one present cash flow)                                   *
         2     pv(one future cash flow)                                    *
         3     pv(perpetuity)                                              *
         4     pv(growing perpetuity)                                      *
         5     pv(annuity)                                                 *
         6     pv(growing annuity)                                         *
         7     fv(annuity)                                                 *
         8     fv(growing annuity)                                         *
           * ------------------------------------------------------------- *
Make a choice (or Esc to stop):
///////////////////////////////