Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Name: Abdullah Amin Subject: Financial Analytics Assignment: 2

Submitted to: Dr Jaleel Reg: Maf223002 Date: March 27, 2023

Answer the following questions


1-Mention the list of commands used to clean up any of the object or for
several objects.
Answer:
In R software, there are several commands that can be used to clean up objects or variables in the
workspace. Here are some commonly used commands:
1. remove(): The remove() function is used to remove a specific object from the workspace
2. rm(): The rm() function is also used to remove a specific object from the workspace. It
can be used in the same way as the remove() function.
3. ls(): The ls() function is used to list all the objects in the workspace.
4. rm(list = ls()): The rm(list = ls()) function is used to remove all objects from the
workspace.
5. gc(): The gc() function is used to free up memory by removing unused objects from the
workspace.
Overall, these are some commonly used commands in R software for cleaning up objects or
variables in the workspace.

2- Explain in detail the treatment of missing values in R


Answer:
Missing values are a common problem in data analysis, and R software provides several
functions for dealing with them. Here are some methods for treating missing values in R:
Checking for missing values: Before treating missing values, it's important to check if they
exist in the dataset. The is.na() function can be used to check for missing values in R. For
example:
is.na(data)
This will return a logical vector indicating whether each value in the dataset is missing or not.
Removing missing values: If the missing values are relatively few, it may be appropriate to
remove them from the dataset. The na.omit() function can be used to remove rows with missing
values. For example:
clean_data <- na.omit(data)
This will create a new dataset "clean_data" without any rows that contain missing values.
Imputing missing values: If the missing values are relatively many or the missing data is
systematic, it may be appropriate to impute the missing values using statistical methods. The
simplest method for imputing missing values is to replace them with the mean or median of the
non-missing values for that variable. The mean() or median() functions can be used to calculate
the mean or median of a variable. For example:
Name: Abdullah Amin Subject: Financial Analytics Assignment: 2
Submitted to: Dr Jaleel Reg: Maf223002 Date: March 27, 2023

mean_value <- mean(data$variable, na.rm = TRUE)


data$variable[is.na(data$variable)] <- mean_value
This will replace missing values in the "variable" column with the mean value of that column.
Using specialized imputation functions: R also provides several specialized functions for
imputing missing values, such as the mice() function, which can perform multiple imputation,
and the missForest() function, which can use random forest algorithms to impute missing values.
Overall, R software provides several options for dealing with missing values, including removing
them, imputing them using statistical methods, or using specialized imputation functions. The
choice of method will depend on the specific characteristics of the dataset and the research
question being addressed.

You might also like