1 R

1.1 Create template tables

1.2 Import & Export

1.2.1 Import

Import fast using httpcashe

Improving efficiency in importing

Import all files in a folder

Import all files in a folder. In the example below files are named “2020-05-05 Saldo”. Import and create a table where the date of the filename is used in a column. Change name for column 1 and 2.

Map has similiar functionality to lapply. When you add _dfr it will generate data.frames and that these is merged.

Import all files in a folder with conditions of name

Use pattern to set the conditions which files that should be imported. For example, those who ends with “Saldo.csv” as below. Regexp (see http://jkorpela.fi/perl/regexp.html) is used in pattern. For example, you need to use \. for the dot. Also, ^ can be used to determine the beginning of a string while $ is used to set the end. pattern = "^.Saldo\.csv$"*

Import all excel files in a folder with condition of name

Import excel from web

Import excel from web by downloading it temp

1.3 Tidy & Transform

1.3.3 Join and Merge

Join tables

Different ways to join tables.

Join tables on multiple conditions

Join Tables on multiple conditions

Merge Data Frames

Merge Data Frames in R: Full and partial match

1.3.4 Transforming data with Apply etc

apply(), lapply(), sapply(), tapply()

apply()

lapply()

sapply()

tapply()

1.3.5 Tally-function

Tally()

Tally is a useful wrapper for summarise with grouping conditions. In the example below we have a data set with countries. For US, there are no aggregate number, so we need to summarize each state.

## Iteration with purrr

Purrr: map functions map() makes a list map_lgl() makes a logical vector map_int() makes an integer vector map_dbl() makes a double vector map_chr() makes a character vector

1.3.6 Mapping over multiple arguments

map2

Purrr pattern finders

1.6 Misc

1.6.10 Loops

1.6.10.1 For loop example

Creates a non-linear function by using the polynomial of x between 1 and 4 and we store it in a list

For loop over a matrix

A matrix has 2-dimension, rows and columns. To iterate over a matrix, we have to define two for loop, namely one for the rows and another for the column.

1.6.10.2 For loop example

Creates a non-linear function by using the polynomial of x between 1 and 4 and we store it in a list

1.6.10.3 For loop and while loop

Function for Right and Left

Functions for Right and Left.

Bloomberg API in R

Blmrg API with package Rblpapi

1.8 Web Scraping

1.9 Useful functions / expressions

1.9.3 unique

Example: get all unique values in a column