- Day 1 - Getting started
- Day 2 - Functions & Spark
- Day 3 - Tidyverse
- Day 4 - Plotly
- Day 5 - Shiny Introduction
- Day 6 - Reactivity
- Day 7 - Modules
- Day 8 - Shiny Project
January, 2018
Example 1 - Hello World
myFunction<-function(){ print("Hello World") } myFunction()
## [1] "Hello World"
Example 2 - with inputs
myFunction<-function(a,b=2){ total<-a+b return(total) } myFunction(1,1)
## [1] 2
myFunction(1)
## [1] 3
Example 3 - using titanic data and glm function to fit a logistic regression
install.packages("titanic") library(titanic) fit<-glm( data = titanic_train, formula = Survived ~ Sex + Age + Pclass, family = "binomial" )
Example 4 - use 'rio' package to read and write (smallish) data from files
install.packages("rio") data<-rio::import(file = "Data/titanic_train.csv",setclass = "tbl",integer64="double") rio::export(x = titanic_train,file = "Data/titanic_train.csv")
In R there are many ways to repeat the same calculations many times
When working with big data use Spark Spark is much faster than working with just R and can handle data that is of very very large size Note that not all R functions work in Spark
install.packages("sparklyr") library(sparklyr) spark_home_set("C:/Spark/spark-2.2.1-bin-hadoop2.7") sc<-spark_connect(master="local") # Create a connection to spark # Do all your analysis spark_disconnect(sc)
data<-spark_read_csv( sc, "titanic", "Data/titanic_train.csv", memory = FALSE, overwrite = TRUE ) #import from R import_iris<-copy_to(sc,iris,"spark_iris",overwrite=TRUE)
ifelse( x^2 + y^2 <=1, TRUE, FALSE)
4*in/iterations