Professional Documents
Culture Documents
Random Sampling
K2Analytics.co.in
K2Analytics.co.in
K2Analytics.co.in
K2Analytics.co.in
K2Analytics.co.in
Summarizing
data_frame [ row, col ]
data_frame [ row, ]
data_frame [, col ]
data_frame [col ]
K2Analytics.co.in
Merging Data
Let us first get the two datasets required for merging and note we
will build on this for our logistic regression
Merge lr_ds1 and lr_ds2 to create our Logistic Regression lr_ds data
frame to be used in subsequent steps
K2Analytics.co.in
K2Analytics.co.in
10
K2Analytics.co.in
11
K2Analytics.co.in
12
13
Data Sorting
Lets say we want to sort our data frame by Age and Holding_Period
Use order() to sort;
Prefix minus - sign for descending sort
Note: Usage of attach(); because of attach() we do not need to prefix column names by data frame name
To sort vectors you can use sort() function
K2Analytics.co.in
14
K2Analytics.co.in
15
K2Analytics.co.in
16
K2Analytics.co.in
17
K2Analytics.co.in
18
K2Analytics.co.in
19
K2Analytics.co.in
20
K2Analytics.co.in
21
tapply
K2Analytics.co.in
22
Using Functions in R
Commonly used mathematics functions
Commonly used summary functions
Commonly used string functions
Creating user defined functions
Local and Global variables
K2Analytics.co.in
24
K2Analytics.co.in
25
K2Analytics.co.in
26
27
K2Analytics.co.in
28
29
R Programming Structures
For Loops
While Loops
If-Else
Arithmetic and Boolean Operators
Loops
For Loop
for (condition)
{
Statements
}
While Loop
while (condition)
{
statements
}
K2Analytics.co.in
31
IF-ELSE
IF-ELSE Syntax
if (condition) { statements }
if (condition) { statements } else {statement}
K2Analytics.co.in
32
K2Analytics.co.in
33
Description
+-*/
^ **
%%
%/%
Less Than, Greater Than, Less Than or Equal To, Greater Than or Equal To
== !=
& &&
AND
OR
||
Negation
%in%
K2Analytics.co.in
34
Histogram
K2Analytics.co.in
36
Pareto Chart
K2Analytics.co.in
37
Box Plot
K2Analytics.co.in
38
Note:
levels give you the distinct values in Factor
length gives you the number of values in
vector returned by levels
For col (colours) we are using their
corresponding values like 2 for Red, 3 for
Green, 4 for Blue
1 is for Black as such starting from 2; and
hence the need for +1
K2Analytics.co.in
39
Pie Chart
K2Analytics.co.in
40
Bar Plot
K2Analytics.co.in
41
K2Analytics.co.in
42
Scatter Plot
K2Analytics.co.in
43
Scatter Plot
If we simply use the
plot with data frame
name then R will
compute scatter
plot for all possible
combinations so
be careful while
working with big
data sets. It will
hang the machine
K2Analytics.co.in
44
Line Plot
K2Analytics.co.in
45
Overlaying Charts
K2Analytics.co.in
46
Thank you
End of Part 2