R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Including Plots

You can also embed plots, for example:

library(ggplot2)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(later)
library(gridExtra)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following object is masked from 'package:gridExtra':
## 
##     combine
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(tidyr)
dfrNifty <- read.csv("C:/Users/admin/Desktop/Pooja p/R-Files1/nifty-data.csv", header=T, stringsAsFactors=F)
head(dfrNifty)
##      RecDate Mkt Series  Sector     Symbol NameOfTheSecurityInNse
## 1 2014-12-01   N     EQ  Cement        ACC            ACC LIMITED
## 2 2014-12-01   N     EQ  Cement  AMBUJACEM     AMBUJA CEMENTS LTD
## 3 2014-12-01   N     EQ    FMCG ASIANPAINT   ASIAN PAINTS LIMITED
## 4 2014-12-01   N     EQ FinSrvc   AXISBANK      AXIS BANK LIMITED
## 5 2014-12-01   N     EQ    Auto BAJAJ-AUTO     BAJAJ AUTO LIMITED
## 6 2014-12-01   N     EQ FinSrvc BANKBARODA         BANK OF BARODA
##   PrevClose OpenPrice HighPrice LowPrice ClosePrice TradeValue TradeQty
## 1   1475.35   1476.00    1479.7  1461.15    1470.95  202553784   137735
## 2    229.90    229.25     233.5   228.55     230.35  348745207  1512068
## 3    744.70    753.95     802.2   753.10     797.05 2576774020  3291847
## 4    481.20    484.40     493.2   481.15     489.15 2267475272  4634567
## 5   2640.80   2642.50    2660.8  2613.05    2636.30  527142941   199683
## 6   1087.20   1091.00    1104.7  1074.35    1082.65 1447645708  1328730
##   IndSec CoprInd Trades X52W_High X52W_Low
## 1      Y           6422   1564.65   970.15
## 2      Y          19712    243.80   150.10
## 3      Y          68366    802.20   460.20
## 4      Y          53177   2043.05   369.05
## 5      Y          10121   2695.00  1793.20
## 6      Y          29489   1104.70   511.15
View(dfrNifty)

#Compute AvgPrice=TradeValue/TradeQty #Line Graph showing Daily AvgPrice of all Banks.

dfrNifty$AvgPrice <- " "
View(dfrNifty)
average<- function(tradev,tradeq) {
  strRetValue <- (tradev/tradeq)
  return (strRetValue)
}
dfrNifty$AvgPrice <- mapply(average,
                            dfrNifty$TradeValue,
                            dfrNifty$TradeQty
)
View(dfrNifty)

cat("\014")
#Line Graph showing Daily AvgPrice of all Banks.
# simple line plot
# requires numeric column or date column as x-axis
# requires numeric column as y-axis
# plots line-graph
dfrNifty.Tmp <- subset(dfrNifty, Sector=="FinSrvc")
dfrNifty.Tmp$AvgPrice <- dfrNifty.Tmp$TradeValue/dfrNifty.Tmp$TradeQty

p1<- ggplot(dfrNifty.Tmp, aes(x=as.Date(RecDate), y=AvgPrice,group=Symbol)) +
  geom_line(color="red", linetype=1) +
  geom_point(color="black", shape=20) +
  labs(title="Average Price") +
  labs(x="Symbol") +
  labs(y="Average Price")
ggplotly(p1)

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.