R
and our platform

Winston Chen @ Fliptop
Going to Cover
Setting it up locally
R very basics
Our Current R Infrastructure
MongoDB and MySql Integration
The Follow-ups?
Installation On Your Local
Come On! We are developers.
http://cran.csie.ntu.edu.tw/

Just download it and install yourself.
Play with your RStudio
R Very Basics
A bunch of functions and data types to work with data.
- Not like C/java/scala/python. Don’t built products with it.
- It works with Matrices, or super/sub types of it:
- Vectors, Matrices, Data Frames… etc
- So, Think in tabular ways.
- All the operations based upon matrices.
R Data Types
Atomic
Vectors
Matrix
Lists
Data Frame
Atomic
Numeric: x = 10.55; class(x)
Integer: y = as.integer(x); is.integer(y)
Complex: z = 1 + 2i
Logical: TRUE/FALSE
Character: “nothing more than string”
String concanation: paste(“Adam”, ”Smith”)
[http://www.r-tutor.com/r-introduction/basic-data-types]
Vectors
mylovelyvector <- c(2, 3, 5)
Combining vectors:
combined_vectors <- c(n, s)

Indexing:
mylovelyvector[1]
Multiple Indexing:
mylovelyvector[c(2,3)]
Ranging:
mylovelyvector[1:2]
[http://www.r-tutor.com/r-introduction/vector]
Matrix
> A = matrix(
c(2, 4, 3, 1, 5, 7), # the data elements
nrow=2,

# number of rows

ncol=3,

# number of columns

byrow = TRUE)

>A

# fill matrix by rows

# print the matrix

[,1] [,2] [,3]
[1,]

2

4

3

[2,]

1

5

7
Matrix 2
Transpose:
tA <- t(A)

[http://www.r-tutor.com/r-introduction/matrix/matrixconstruction]
List
A list is a generic vector containing other objects.
n = c(2, 3, 5)
s = c("aa", "bb", "cc", "dd", "ee")
b = c(TRUE, FALSE, TRUE, FALSE, FALSE)
x = list(n, s, b, 3) # x contains copies of n, s, b

[http://www.r-tutor.com/r-introduction/list]
Data Frame
Basically like a mysql table.
Building one:
n = c(2, 3, 5)
s = c("aa", "bb", "cc")
b = c(TRUE, FALSE, TRUE)
df = data.frame(n, s, b)
Data Frame 2
head(df, n=10)
names(df)
df[2,3]
df[2,]
df[,1]
df$s

#df[,”s”]
Data Frame 3
Subsetting data frames:
df[1]
df[“s”]
df[c("s", "b")]
subset(df, n<=3)
Adding two data frames together:
combined <- rbind(df, df2)
data <- read.csv("/Path/To/Ur/CSV/R_Example.csv",
header=TRUE)
[http://www.r-bloggers.com/select-operations-on-r-dataframes/]
Data Frame 4
We wanna explore data:
select * from df where b=true
can be translated into
df_sub1 <- df[df$b==TRUE,]

Then, the holy grail: something like sql join
k = c('the','X','Men')
s = c("aa", "bb", "cc")
z = c(3.1415961, 124235243, 2309)
df2 = data.frame(k, s, z)
merged <- merge(df, df2, 's') #tada!!!
QA and Onward
Who is up to a R study group?
- Plotting (ggplot)
- etc…

The Very ^ 2 Basics of R

  • 1.
  • 2.
    Going to Cover Settingit up locally R very basics Our Current R Infrastructure MongoDB and MySql Integration The Follow-ups?
  • 3.
    Installation On YourLocal Come On! We are developers. http://cran.csie.ntu.edu.tw/ Just download it and install yourself.
  • 4.
  • 5.
    R Very Basics Abunch of functions and data types to work with data. - Not like C/java/scala/python. Don’t built products with it. - It works with Matrices, or super/sub types of it: - Vectors, Matrices, Data Frames… etc - So, Think in tabular ways. - All the operations based upon matrices.
  • 6.
  • 7.
    Atomic Numeric: x =10.55; class(x) Integer: y = as.integer(x); is.integer(y) Complex: z = 1 + 2i Logical: TRUE/FALSE Character: “nothing more than string” String concanation: paste(“Adam”, ”Smith”) [http://www.r-tutor.com/r-introduction/basic-data-types]
  • 8.
    Vectors mylovelyvector <- c(2,3, 5) Combining vectors: combined_vectors <- c(n, s) Indexing: mylovelyvector[1] Multiple Indexing: mylovelyvector[c(2,3)] Ranging: mylovelyvector[1:2] [http://www.r-tutor.com/r-introduction/vector]
  • 9.
    Matrix > A =matrix( c(2, 4, 3, 1, 5, 7), # the data elements nrow=2, # number of rows ncol=3, # number of columns byrow = TRUE) >A # fill matrix by rows # print the matrix [,1] [,2] [,3] [1,] 2 4 3 [2,] 1 5 7
  • 10.
    Matrix 2 Transpose: tA <-t(A) [http://www.r-tutor.com/r-introduction/matrix/matrixconstruction]
  • 11.
    List A list isa generic vector containing other objects. n = c(2, 3, 5) s = c("aa", "bb", "cc", "dd", "ee") b = c(TRUE, FALSE, TRUE, FALSE, FALSE) x = list(n, s, b, 3) # x contains copies of n, s, b [http://www.r-tutor.com/r-introduction/list]
  • 12.
    Data Frame Basically likea mysql table. Building one: n = c(2, 3, 5) s = c("aa", "bb", "cc") b = c(TRUE, FALSE, TRUE) df = data.frame(n, s, b)
  • 13.
    Data Frame 2 head(df,n=10) names(df) df[2,3] df[2,] df[,1] df$s #df[,”s”]
  • 14.
    Data Frame 3 Subsettingdata frames: df[1] df[“s”] df[c("s", "b")] subset(df, n<=3) Adding two data frames together: combined <- rbind(df, df2) data <- read.csv("/Path/To/Ur/CSV/R_Example.csv", header=TRUE) [http://www.r-bloggers.com/select-operations-on-r-dataframes/]
  • 15.
    Data Frame 4 Wewanna explore data: select * from df where b=true can be translated into df_sub1 <- df[df$b==TRUE,] Then, the holy grail: something like sql join k = c('the','X','Men') s = c("aa", "bb", "cc") z = c(3.1415961, 124235243, 2309) df2 = data.frame(k, s, z) merged <- merge(df, df2, 's') #tada!!!
  • 16.
    QA and Onward Whois up to a R study group? - Plotting (ggplot) - etc…