Lec3 - Variables and Datatypes - Vectors and Lists
Lec3 - Variables and Datatypes - Vectors and Lists
In this lecture
Variables
Basic data types
R objects
◦ Vectors
◦ Lists
Variables
Variables
Variable names - Rules Examples
Predefined constants
Constant Symbol in R
Pi pi
letters a,b,c,…….x,y,z
LETTERS A,B,,…..,X,Y,Z
Months in a month.name,
year month.abb
Data types
“a”,”b”,”c”,….,”x”,”y”,”z”,”@”,”#”,”$”, “”,”*”,
Character
“1”,”2”,… etc..
Note : Not all coercions are possible and if attempted will return “NA” as output
Sample Codes
Basic objects
Object Values
Vectors
Vectors
• Vector : an ordered collection of basic data types of given
length
# Vectors Example
X = c(2.3,4.5,6.7,8.9)
print(X)
Lists
Manipulating lists
A list can be modified by accessing components & replacing them
Concatenation of lists
Two lists can be concatenated using the concatenation function,
c(list1, list2)