Dataframes
 A dataframe in R is an 2D object where columns can contain data of different classes and types.
 This is very useful for practical storage
 Dataframes can be created by using
as.data.frame()
on applicable objects or column or row binding vectors usingcbind.data.frame()
orrbind.data.frame()
Variables
 Variable Assignment: There are two ways to assign a value to a variable, The operators are
<
and=
, with the first being preffered
x < 2
x
y = 5
y
 The arrow operator can be used in other direction
3 > z
 The assignment operation can be used succesively to assign a value to multiple variable simulatenous
 A more laborious though sometimes necessary way to assign variable is to use
assign
function
assign("j", 10)
j
 Naming convention:
 Variable names can contain any combination of alpha numeric characters with periods(.) and underscores(_). However the variable name cannot start with a number or underscore
 Removing variables:
 This is easily done by using
remove
or its shortcutrm
 Removing variable will free up memory so that R can store more objects, although it deoes not necessarily free up memory from os. To guarntee that, us gc which performs garbage, releasing unused memory to operting system.
 R automatically does garbage collection so this function is not essential
 This is easily done by using
 Ensure we use Google’s R style guide Refer Here
 Refer Here for assignment operators in r
 What’s the difference between
=
and<
Vectors Contd
 Vectors in R are special as R is vecorized language, that means operations applied to each element of the vector automatically without needing to loop the vector
 Examples
 To create a vector we have use 1:10 which generates consecutive numbers
 In R we have a length function which will determine number of elements in vector
> all(y>w)
> TRUE

nchar => find number of characters

Activity 1:
 We have gamber who has played two games "BlackJack" and "Poker"
 His daily profit or loss for black jack are
 Monday => lost 100 $
 Tuesday => gained 200 $
 Wednesday => lost 50 $
 Thursday => lost 100$
 Friday => gained 200 $
 His daily profit or loss for poker are
 Monday => lost 1000 $
 Tuesday => gained 2000 $
 Wednesday => lost 500 $
 Thursday => lost 1000 $
 Friday => gained 2000 $

Represent this in vectors in R

Vector Recycling:
 Repetition of small length as long as completition of operation on long length of vector is called as vector recycling
 Samples:

Naming vectors:

Indexing and slicing vectors

Lets assume we want to get the values from poker
 where we have lost
poker[poker<0]
 where we have gained
poker[poker>0]
Function Documentation
 We can use
help()
Things to Come/Learn in Near Future
 We have simulate coin flip and rolling a dice