Data analysis

Telling the length or we can say the total number of unique companies in the dataset.

R




#unique companies in the dataset
companies <- length(unique(data1$Name))
companies


Output:

505

Telling the lowest closing price in the dataset.

R




# Lowest closing price 
price <- min(data1$close)
price


Output:

1.59

Telling the highest closing price in the dataset.

R




# Highest closing price 
price <- max(data1$close)
price


Output:

2049

Giving the result of the company name with the highest shared volume.

R




# Company with maximum volume
maximum_volume <- data1$Name[which.max(data1$volume)]
maximum_volume


Output:

'VZ'

Giving the result of the company name with the minimum shared volume.

R




# Company with minimum volume
minimum_volume <- data1$Name[which.min(data1$volume)]
minimum_volume


Output:

'BHF'

We calculate the average closing price by taking the mean of the close column in the dataset data1

R




# Average price of closing
mean_price <- mean(data1$close)
mean_price


Output:

83.0433.49787651

We determine the total trading volume by summing up the values in the volume column of the dataset data1.

R




# Total volume 
total_volume <- sum(data1$volume)
total_volume


Output:

2675376439690

We find the company with the longest consecutive days of price increases by identifying the corresponding “Name” value where the condition for consecutive price increases is met.

R




# We will see the Company which have the
# longest consecutive days of price increases
price_increase <- data1$Name[rle(data1$close > lag(data1$close))$values &
                             rle(data1$close > lag(data1$close))$lengths > 1][1]
price_increase


Output:

'AAL'

We find the company with the longest consecutive days of price decreases by identifying the corresponding “Name” value where the condition for consecutive price decreases is met.

R




# We will see the Company which have the longest consecutive days of price decreases
price_decrease <- data1$Name[rle(data1$close < lag(data1$close))$values &
                             rle(data1$close < lag(data1$close))$lengths > 1][1]
price_decrease


Output:

'AAL'

S&P 500 Companies Data Analysis Tutorial using R

R is a powerful programming language and environment for statistical computation and data analysis. It is backed by data scientists, accountants, and educators because of its various features and capabilities. This project will use R to search and analyze stock market data for S&P 500 companies.

Tidyverse, ggplot2, and dplyr are just a few of the many libraries provided by R Programming Language that simplify data processing, visualization, and statistical modeling. These libraries allow us to perform many tasks such as data cleaning, filtering, aggregation, and visualization.

In this work, we will analyze the S&P 500 stock market dataset using these packages using R capabilities.

Hey! Hey! Hey! Welcome, adventurous data enthusiasts! Grab your virtual backpacks, put on your data detective hats, Ready to unravel this mysterious project journey with me.

  • Dataset introduction – All files contain the following column.
  • Date – In format: yy-mm-dd.
  • Open – Price of the stock at the market open (this is NYSE data so everything is in USD).
  • High – The highest value achieved for the day.
  • Low Close – The lowest price achieved on the day.
  • Volume – The number of transactions.
  • Name – The stock’s ticker name.

Similar Reads

Installing and Loading the Tidyverse Package

Our adventure begins with the mysterious meta-package called “tidyverse.” With a simple incantation, “library(tidyverse)” we unlock the powerful tools and unleash the magic of data manipulation and visualization.:...

Data Exploration & Analysis

...

Handling missing values

...

Data Visualization

...

Data analysis

Our adventure begins with a simple task—discovering what lies within our dataset. We load the data and take a sneak peek. With the “head()” function, we unveil the first 10 rows. We revel in the joy of exploring the dimensions of our dataset using “dim()“....

Feature Engineering

...