Adding new columns or rows to a data frame
Indexing/ sub-setting data frames
Importing Data from Excel (Comma Separated Value)
Importing data from the web
Descriptive Statistics
Visualizing the Results
DATA ENTRY AND IMPORTATION INTO R
Course: ACTM 311 - Computational Methods and Data Analysis III
School of Mathematics
Group: Bachelor of Science in Actuarial Science - Y3S1
October 11, 2022
Onsoti Alex N. COMPUTATIONAL METHODS AND DATA ANALYSIS III 1/50
, Data Frames
Adding new columns or rows to a data frame
Indexing/ sub-setting data frames
Importing Data from Excel (Comma Separated Value)
Importing data from the web
Descriptive Statistics
Visualizing the Results
General Outline
1 Data Frames
Creating data frames
Properties
Creating data frames from other objects
Creating data frames using cbind and rbind
2 Adding new columns or rows to a data frame
Adding a new column
Adding a new row
3 Indexing/ sub-setting data frames
4 Importing Data from Excel (Comma Separated Value)
5 Importing data from the web
6 Descriptive Statistics
7 Visualizing the Results
Onsoti Alex N. COMPUTATIONAL METHODS AND DATA ANALYSIS III 2/50
, Data Frames
Adding new columns or rows to a data frame
Creating data frames
Indexing/ sub-setting data frames
Properties
Importing Data from Excel (Comma Separated Value)
Creating data frames from other objects
Importing data from the web
Creating data frames using cbind and rbind
Descriptive Statistics
Visualizing the Results
Creating data frames
A data frame is a collection of column vectors/factors of the same length.
The columns are the vectors/factors which contain data for a single variable (e.g
policyholder’s names, ages and smoker status)
The rows represent a single observation (e.g a single policyholder)
Note that whilst each column (i.e vector/factor) contains data of the same type,
the different columns (i.e vectors/factors) can be different data types.
In the example above we have character data for the first column, numeric data
for the second column and logical data for the third column.
Onsoti Alex N. COMPUTATIONAL METHODS AND DATA ANALYSIS III 3/50
, Data Frames
Adding new columns or rows to a data frame
Creating data frames
Indexing/ sub-setting data frames
Properties
Importing Data from Excel (Comma Separated Value)
Creating data frames from other objects
Importing data from the web
Creating data frames using cbind and rbind
Descriptive Statistics
Visualizing the Results
Creating data frames
You can check out whether an object is a data frame by using is.data.frame().
The dimensions are called rows and columns and the numbers of each can be
found by using the nrow() and ncol() commands respectively.
Alternatively, you could use the dimensions command dim() to get both the
number of rows and columns.
To create a data frame from scratch we use the data.frame( ) command.
This will create a data frame out of a list of vectors (or other data frames):
d a t a . frame (< v e c t o r 1 >, <v e c t o r 2 > , . . . )
Onsoti Alex N. COMPUTATIONAL METHODS AND DATA ANALYSIS III 4/50