2. https://www.r-project.org/
Essential tools:
RGUI Basic R processing,
RScript to run batch scripts,
RCMD (to install in Unix/Linux) variants
RStudio is a compelling tool – though defer RStudio until you know R very we
ll – tools are limiting you – bad idea to start with RStudio to learn the la
nguage, IMHO.
Reference Sites: (that I often use, don’t leave home without it)
https://www.r-bloggers.com
https://nabble.com/
http://rfunction.com
https://stackoverflow.com/
https://stats.stackexchange.com/
https://www.datasciencemadesimple.com/
http://www.r-tutor.com/
There are thousands if not more, useful R sites you can learn from
Again to do what you want to get done…otherwise you will be sucked into
vortex..
…
Chapter-02-R-Tutorial file:///C:/Users/rk215/Documents/R-Tutorial.html#Learning_R_to_do_D...
2 of 31 10/18/2020, 4:30 AM
3. ls()
## character(0)
X<-5
7->Y
ifelse(X<Y,'X is Less than Y', 'X is atleast equal to Y')
## [1] "X is Less than Y"
vec<-1:13
is.vector(vec)
## [1] TRUE
vec[4]
## [1] 4
by2<-seq(1,13,2)
(xy2<-seq(1,13,2))
## [1] 1 3 5 7 9 11 13
xy2[4]
## [1] 7
Chapter-02-R-Tutorial file:///C:/Users/rk215/Documents/R-Tutorial.html#Learning_R_to_do_D...
3 of 31 10/18/2020, 4:30 AM
14. ## PassengerId Survived Pclass
## 1 1 0 3
## 2 2 1 1
## 3 3 1 3
## 4 4 1 1
## 5 5 0 3
## 6 6 0 3
## Name Sex Age SibSp Pa
rch
## 1 Braund, Mr. Owen Harris male 22 1
0
## 2 Cumings, Mrs. John Bradley (Florence Briggs Thayer) female 38 1
0
## 3 Heikkinen, Miss. Laina female 26 0
0
## 4 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35 1
0
## 5 Allen, Mr. William Henry male 35 0
0
## 6 Moran, Mr. James male NA 0
0
## Ticket Fare Cabin Embarked
## 1 A/5 21171 7.2500 S
## 2 PC 17599 71.2833 C85 C
## 3 STON/O2. 3101282 7.9250 S
## 4 113803 53.1000 C123 S
## 5 373450 8.0500 S
## 6 330877 8.4583 Q
dim(titanic)
## [1] 891 12
table(mdf==rmdf)
##
## TRUE
## 19308
cumprod(dim(mdf)) #rows ^ columns the number of elements all of them match a
s they should
Chapter-02-R-Tutorial file:///C:/Users/rk215/Documents/R-Tutorial.html#Learning_R_to_do_D...
14 of 31 10/18/2020, 4:30 AM
15. ## [1] 6436 19308
nrow(rmdf)* ncol(rmdf)
## [1] 19308
quantmod::getSymbols(c("IBM","SPY"),from='2020-01-01')
## Registered S3 method overwritten by 'quantmod':
## method from
## as.zoo.data.frame zoo
## 'getSymbols' currently uses auto.assign=TRUE by default, but will
## use auto.assign=FALSE in 0.5-0. You will still be able to use
## 'loadSymbols' to automatically load data. getOption("getSymbols.env")
## and getOption("getSymbols.auto.assign") will still be checked for
## alternate defaults.
##
## This message is shown once per session and may be disabled by setting
## options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
## [1] "IBM" "SPY"
dim(IBM)
## [1] 201 6
#dim(JNJ)
#quantmod::getSymbols(c("SPY"),from='2020-01-01')
head(IBM)
Chapter-02-R-Tutorial file:///C:/Users/rk215/Documents/R-Tutorial.html#Learning_R_to_do_D...
15 of 31 10/18/2020, 4:30 AM
21. SELECT A.p1,
A.p2,
A.p1p2c / B.p1c AS condProb
FROM (SELECT apid P1,
bpid P2,
Count(*) P1P2C
FROM (SELECT A.did AS ADID,
A.cid AS ACID,
A.pid AS APID,
B.did AS BDID,
B.cid AS BCID,
B.pid AS BPID
FROM purchases A
JOIN purchases B
ON A.cid = B.cid
AND A.did = B.did
AND A.pid < B.pid) X
GROUP BY apid,
bpid) A
JOIN (SELECT pid AS P1,
Count(*) P1C
FROM purchases
GROUP BY pid) B
ON A.p1 = B.p1
ORDER BY condprob DESC;
sqlstr<-"select A.P1,A.P2, (A.P1P2C*100)/B.P1C as condProb from ( Select API
D P1,BPID P2,count(*) P1P2C from ( select A.DID as
ADID, A.CID as ACID , A.PID as APID , B.DID as BDID, B.CID as BCID , B.PID a
s BPID from purchases A join purchases B on
A.CID=B.CID AND A.DID=B.DID AND A.PID < B.PID ) X group by APID,BPID ) A jo
in (select PID as P1, count(*) P1C from purchases group by PID) B on A.P1=B.
P1 order by condProb desc"
sqlstr
## [1] "select A.P1,A.P2, (A.P1P2C*100)/B.P1C as condProb from ( Select APID
P1,BPID P2,count(*) P1P2C from ( select A.DID asnADID, A.CID as ACID , A.P
ID as APID , B.DID as BDID, B.CID as BCID , B.PID as BPID from purchases A j
oin purchases B onnA.CID=B.CID AND A.DID=B.DID AND A.PID < B.PID ) X group
by APID,BPID ) A join (select PID as P1, count(*) P1C from purchases group b
y PID) B on A.P1=B.P1 order by condProb desc"
Chapter-02-R-Tutorial file:///C:/Users/rk215/Documents/R-Tutorial.html#Learning_R_to_do_D...
21 of 31 10/18/2020, 4:30 AM