Learn R Programming

REN (version 0.1.0)

prepare_data: Prepare Data for Portfolio Analysis

Description

This function prepares the input data by filtering based on a specified date range, removing the date column, and handling missing values. It also generates time-related columns and returns the processed data.

Usage

prepare_data(
  dat,
  date_column_index = 1,
  start_date = "19990101",
  end_date = "20231231"
)

Value

A list containing the following components:

x

A matrix of the filtered data with missing values handled.

mon

A vector of integers representing the number of months from the first date in the data.

count

A vector of the number of entries per month.

Date

A vector of Date objects representing the filtered dates.

Arguments

dat

A data frame or matrix where the first column is the date and the remaining columns are the data.

date_column_index

The index of the date column in the input data. Default is 1.

start_date

A character string specifying the start date for filtering the data in 'YYYYMMDD' format. Default is '19990101'.

end_date

A character string specifying the end date for filtering the data in 'YYYYMMDD' format. Default is '20231231'.

Examples

Run this code
data <- data.frame(Date = c("19990101", "19990115", "19990201", "19990301", "19990315", "19990401"),
Var1 = c(1, 2, -99.99, 4, 5, -99.99),
Var2 = c(3, -99.99, 6, 7, 8, 9),
Var3 = c(10, 11, 12, 13, -99.99, 15))
result <- prepare_data(data, date_column_index = 1, start_date = '19990101', end_date = '19990430')
print(result)

Run the code above in your browser using DataLab