Lecture III: Data Handling
R is case sensitive
Anything that follow the # symbol is intepreted as a comment and is ignored by R
in R, commands are generally seprated by a new line, but you can also use a semicolon
If a continuation prompt + appears in the console after you execute your code, this means that you haven’t completed your code correctly
This often happens if you forget to close a bracket and is especially common with nested brackets
Creating an Object
Simply name an object
To Name an object use (n←22)
the ← symbol is callled assignment operator
The assignment operator is a composite symbol comprised of a less than symbol and a hyphen
Not equal to is an exclamation point and an equation sign
When an object is created, it will get diplayed in the envrionment
Creating a Object Using Data Types in R
1.1 Numberic
REprensents wole and decimal numbers
Default type fro numbers in R
1.2 Integer
Whole numbers only
Must be explcity marked with an
Asking class and typeof is the same thing
Naming an object
keep is short and infromative
area_of_the_triangle (using underscores)
AreaOfTheTriangle (utilising case sensitivity)
area.of.the.triangle
LImitations
an object name cannot start with a number or a dot folloed by a number (i.e. 2my_variable or /2my_variable)
you should also avoid using non-alphanumeric characters in your object names
In addition, make sure you don’t name your objects with reserved words (e.g. TRUE, NA)
It’s never good a idea to give your object the same name as a built-in function (such as mean, class, data)
Creating a vector
the c() function is short for concatenate and we use it to join together a series of values and store them in a data structure called a “vector“
When you use a function in R, the function name is always followed by a pair of round brackets
The arguments of a function are palced inside the round brackers and are seprated by commas
Operating Vectors
Positional index: to extract elements based on their position we simply write the position inside the []
Logical index: Logical expression will help if you are looking for more than one piece of data
Creating a matric
matrix (1:6,2,3)
matrix(data=,,,)