A stock market is where buyers and sellers trade shares of a company, and is one of the most popular ways for individuals and companies to invest money. The size of the world stock market is now estimated to be in the trillions. The largest stock market in the world is the New York Stock Exchange (NYSE), located in New York City. About 2,800 companies are listed on the NSYE. In this problem, we’ll look at the monthly stock prices of five of these companies: IBM, General Electric (GE), Procter and Gamble, Coca Cola, and Boeing. The data used in this problem comes from Infochimps.
Download and read the following files into R, using the read.csv function: IBMStock.csv, GEStock.csv, ProcterGambleStock.csv, CocaColaStock.csv, and BoeingStock.csv. (Do not open these files in any spreadsheet software before completing this problem because it might change the format of the Date field.)
Call the data frames “IBM”, “GE”, “ProcterGamble”, “CocaCola”, and “Boeing”, respectively. Each data frame has two variables, described as follows:
Date: the date of the stock price, always given as the first of the month. StockPrice: the average stock price of the company in the given month. In this problem, we’ll take a look at how the stock dynamics of these companies have changed over time.
Before working with these data sets, we need to convert the dates into a format that R can understand. Take a look at the structure of one of the datasets using the str function. Right now, the date variable is stored as a factor. We can convert this to a “Date” object in R by using the following five commands (one for each data set):
IBM$Date = as.Date(IBM$Date, "%m/%d/%y")
GE$Date = as.Date(GE$Date, "%m/%d/%y")
CocaCola$Date = as.Date(CocaCola$Date, "%m/%d/%y")
ProcterGamble$Date = as.Date(ProcterGamble$Date, "%m/%d/%y")
Boeing$Date = as.Date(Boeing$Date, "%m/%d/%y")
The first argument to the as.Date function is the variable we want to convert, and the second argument is the format of the Date variable. We can just overwrite the original Date variable values with the output of this function. Now, answer the following questions using the str and summary functions.
Our five datasets all have the same number of observations. How many observations are there in each data set?
summary(ProcterGambleStock)
Date StockPrice
Length:480 Min. : 46.88
Class :character 1st Qu.: 62.48
Mode :character Median : 78.34
Mean : 77.70
3rd Qu.: 89.47
Max. :149.62
What is the earliest year in our datasets?
head(IBMStock$Date)
[1] "1970-01-01" "1970-02-01" "1970-03-01" "1970-04-01" "1970-05-01"
[6] "1970-06-01"
What is the latest year in our datasets?
summary(IBMStock)
Date StockPrice
Min. :1970-01-01 Min. : 43.40
1st Qu.:1979-12-24 1st Qu.: 88.34
Median :1989-12-16 Median :112.11
Mean :1989-12-15 Mean :144.38
3rd Qu.:1999-12-08 3rd Qu.:165.41
Max. :2009-12-01 Max. :438.90
What is the mean stock price of IBM over this time period?
mean(IBMStock$StockPrice)
[1] 144.375
What is the minimum stock price of General Electric (GE) over this time period?
min(GEStock$StockPrice)
[1] 9.293636
What is the maximum stock price of Coca-Cola over this time period?
max(CocaColaStock$StockPrice)
[1] 146.5843
What is the median stock price of Boeing over this time period?
median(BoeingStock$StockPrice)
[1] 44.8834
What is the standard deviation of the stock price of Procter & Gamble over this time period?
sd(ProcterGambleStock$StockPrice)
[1] 18.19414
Let’s plot the stock prices to see if we can visualize trends in stock prices during this time period. Using the plot function, plot the Date on the x-axis and the StockPrice on the y-axis, for Coca-Cola.
This plots our observations as points, but we would really like to see a line instead, since this is a continuous time period. To do this, add the argument type=“l” to your plot command, and re-generate the plot (the character is quotes is the letter l, for line). You should now see a line plot of the Coca-Cola stock price.
Around what year did Coca-Cola has its highest stock price in this time period?
Around what year did Coca-Cola has its lowest stock price in this time period? 1980
Now, let’s add the line for Procter & Gamble too. You can add a line to a plot in R by using the lines function instead of the plot function. Keeping the plot for Coca-Cola open, type in your R console:
lines(ProcterGamble$Date, ProcterGamble$StockPrice)
Unfortunately, it’s hard to tell which line is which. Let’s fix this by giving each line a color. First, re-run the plot command for Coca-Cola, but add the argument col=“red”. You should see the plot for Coca-Cola show up again, but this time in red. Now, let’s add the Procter & Gamble line (using the lines function like we did before), adding the argument col=“blue”. You should now see in your plot the Coca-Cola stock price in red, and the Procter & Gamble stock price in blue.
As an alternative choice to changing the colors, you could instead change the line type of the Procter & Gamble line by adding the argument lty=2. This will make the Procter & Gamble line dashed.
Using this plot, answer the following questions.
In March of 2000, the technology bubble burst, and a stock market crash occurred. According to this plot, which company’s stock dropped more?
plot(CocaColaStock$Date,CocaColaStock$StockPrice)+lines(CocaColaStock$Date,CocaColaStock$StockPrice, col="red")+lines(ProcterGambleStock$Date, ProcterGambleStock$StockPrice, col="blue")+abline(v=as.Date(c("2000-03-01")), lwd=2)
integer(0)
To answer this question and the ones that follow, you may find it useful to draw a vertical line at a certain date. To do this, type the command
abline(v=as.Date(c("2000-03-01")), lwd=2)
in your R console, with the plot still open. This generates a vertical line at the date March 1, 2000. The argument lwd=2 makes the line a little thicker. You can change the date in this command to generate the vertical line in different locations.
Answer these questions using the plot you generated in the previous problem.
Around 1983, the stock for one of these companies (Coca-Cola or Procter and Gamble) was going up, while the other was going down. Which one was going up?
plot(CocaColaStock$Date,CocaColaStock$StockPrice)+lines(CocaColaStock$Date,CocaColaStock$StockPrice, col="red")+lines(ProcterGambleStock$Date, ProcterGambleStock$StockPrice, col="blue")+abline(v=as.Date(c("1983-01-01")), lwd=2)
integer(0)
In the time period shown in the plot, which stock generally has lower values?
#Coca-Cola
Each observation in the dataset represents a motor vehicle theft, and the Arrest variable indicates whether an arrest was later made for this theft. Which month has the largest number of motor vehicle thefts for which an arrest was made?
Let’s take a look at how the stock prices changed from 1995-2005 for all five companies. In your R console, start by typing the following plot command:
plot(CocaCola$Date[301:432], CocaCola$StockPrice[301:432], type="l",
col="red", ylim=c(0,210))
This will plot the CocaCola stock prices from 1995 through 2005, which are the observations numbered from 301 to 432. The additional argument, ylim=c(0,210), makes the y-axis range from 0 to 210. This will allow us to see all of the stock values when we add in the other companies.
Now, use the lines function to add in the other four companies, remembering to only plot the observations from 1995 to 2005, or [301:432]. You don’t need the “type” or “ylim” arguments for the lines function, but remember to make each company a different color so that you can tell them apart. Some color options are “red”, “blue”, “green”, “purple”, “orange”, and “black”. To see all of the color options in R, type colors() in your R console.
(If you prefer to change the type of the line instead of the color, here are some options for changing the line type: lty=2 will make the line dashed, lty=3 will make the line dotted, lty=4 will make the line alternate between dashes and dots, and lty=5 will make the line long-dashed.)
Use this plot to answer the following four questions.
Which stock fell the most right after the technology bubble burst in March 2000?
plot(CocaColaStock$Date[301:432], CocaColaStock$StockPrice[301:432], type="l",
col="red", ylim=c(0,210))+lines(CocaColaStock$Date[301:432],CocaColaStock$StockPrice[301:432], col="red")+lines(ProcterGambleStock$Date[301:432],ProcterGambleStock$StockPrice[301:432], col="yellow")+lines(IBMStock$Date[301:432],IBMStock$StockPrice[301:432], col="green")+lines(GEStock$Date[301:432],GEStock$StockPrice[301:432], col="blue")+lines(BoeingStock$Date[301:432],BoeingStock$StockPrice[301:432], col="black")+abline(v=as.Date(c("2000-03-01")))
integer(0)
Which stock reaches the highest value in the time period 1995-2005?
plot(CocaColaStock$Date[301:432], CocaColaStock$StockPrice[301:432], type="l",
col="red", ylim=c(0,210))+lines(CocaColaStock$Date[301:432],CocaColaStock$StockPrice[301:432], col="red")+lines(ProcterGambleStock$Date[301:432],ProcterGambleStock$StockPrice[301:432], col="yellow")+lines(IBMStock$Date[301:432],IBMStock$StockPrice[301:432], col="green")+lines(GEStock$Date[301:432],GEStock$StockPrice[301:432], col="blue")+lines(BoeingStock$Date[301:432],BoeingStock$StockPrice[301:432], col="black")+abline(v=as.Date(c("2000-03-01")))
integer(0)
In October of 1997, there was a global stock market crash that was caused by an economic crisis in Asia. Comparing September 1997 to November 1997, which companies saw a decreasing trend in their stock price? (Select all that apply.)
plot(CocaColaStock$Date[301:432], CocaColaStock$StockPrice[301:432], type="l",
col="red", ylim=c(0,210))+lines(CocaColaStock$Date[301:432],CocaColaStock$StockPrice[301:432], col="red")+lines(ProcterGambleStock$Date[301:432],ProcterGambleStock$StockPrice[301:432], col="yellow")+lines(IBMStock$Date[301:432],IBMStock$StockPrice[301:432], col="green")+lines(GEStock$Date[301:432],GEStock$StockPrice[301:432], col="blue")+lines(BoeingStock$Date[301:432],BoeingStock$StockPrice[301:432], col="black")+abline(v=as.Date(c("1997-09-01")))+abline(v=as.Date(c("1997-11-01")))
integer(0)
In the last two years of this time period (2004 and 2005) which stock seems to be performing the best, in terms of increasing stock price?
plot(CocaColaStock$Date[301:432], CocaColaStock$StockPrice[301:432], type="l",
col="red", ylim=c(0,210))+lines(CocaColaStock$Date[301:432],CocaColaStock$StockPrice[301:432], col="red")+lines(ProcterGambleStock$Date[301:432],ProcterGambleStock$StockPrice[301:432], col="yellow")+lines(IBMStock$Date[301:432],IBMStock$StockPrice[301:432], col="green")+lines(GEStock$Date[301:432],GEStock$StockPrice[301:432], col="blue")+lines(BoeingStock$Date[301:432],BoeingStock$StockPrice[301:432], col="black")+abline(v=as.Date(c("2004-01-01")))+abline(v=as.Date(c("2005-12-31")))
integer(0)
Lastly, let’s see if stocks tend to be higher or lower during certain months. Use the tapply command to calculate the mean stock price of IBM, sorted by months. To sort by months, use
months(IBM$Date)
as the second argument of the tapply function.
For IBM, compare the monthly averages to the overall average stock price. In which months has IBM historically had a higher stock price (on average)? Select all that apply.(January~December)
tapply(Month, IBMStock$StockPrice, mean)
argument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NAargument is not numeric or logical: returning NA
43.395 43.57285714 44.25238095 45.91380952 48.92 49.184
NA NA NA NA NA NA
50.10952381 51.235 51.60809524 51.71842105 51.827 52.74090909
NA NA NA NA NA NA
53.65666667 53.87809524 54.08956522 54.14105263 54.60105263 54.6752381
NA NA NA NA NA NA
54.95681818 55.25782609 56.15681818 56.42227273 56.9547619 57.0535
NA NA NA NA NA NA
57.90142857 58.13380952 58.20090909 58.62 58.74136364 59.14956522
NA NA NA NA NA NA
59.28333333 59.66333333 59.859 60.02636364 60.68095238 62.03636364
NA NA NA NA NA NA
62.04157895 62.82285714 62.94789474 63.06409091 63.35047619 63.35681818
NA NA NA NA NA NA
63.4935 64.60666667 65.15652174 65.235 65.42304348 65.4915
NA NA NA NA NA NA
66.09 66.17047619 66.27809524 66.595 66.75380952 67.0855
NA NA NA NA NA NA
67.20043478 67.53608696 67.77136364 68.16894737 68.73571429 68.955
NA NA NA NA NA NA
69.46277778 69.92727273 70.16086957 70.61666667 71.56238095 72.40809524
NA NA NA NA NA NA
72.43857143 73.56545455 73.8547619 74.58947368 74.62363636 74.7185
NA NA NA NA NA NA
74.84904762 75.2352381 75.60636364 75.62095238 75.914 77.82521739
NA NA NA NA NA NA
77.99052632 78.02863636 79.25761905 79.58857143 80.27238095 80.53
NA NA NA NA NA NA
80.75428571 80.8735 81.2335 81.32347826 81.54818182 81.5885
NA NA NA NA NA NA
81.68952381 81.76047619 81.85909091 81.98217391 82.06333333 82.13217391
NA NA NA NA NA NA
82.2352381 82.47263158 82.4975 82.56190476 82.61863636 82.72842105
NA NA NA NA NA NA
83.30666667 83.82318182 83.94333333 84.57545455 84.9147619 85.13761905
NA NA NA NA NA NA
85.18857143 85.24380952 85.64095238 86.645 86.72333333 86.80227273
NA NA NA NA NA NA
87.07142857 87.29190476 87.552 87.5965 87.90473684 88.29285714
NA NA NA NA NA NA
88.36095238 88.53857143 88.89095238 89.42 89.49842105 89.98526316
NA NA NA NA NA NA
90.31521739 90.54090909 91.11315789 91.30772727 91.44136364 91.6465
NA NA NA NA NA NA
92.04285714 92.12318182 92.1475 92.32666667 92.73652174 92.86727273
NA NA NA NA NA NA
93.185 93.275 93.34947368 93.3915 93.58952381 93.58956522
NA NA NA NA NA NA
93.60818182 94.00272727 94.24818182 94.42363636 94.5615 94.7905
NA NA NA NA NA NA
94.9625 95.13866667 95.15727273 95.81590909 96.222 96.5505
NA NA NA NA NA NA
96.5735 96.87590909 96.9747619 97.14095238 97.36636364 97.447
NA NA NA NA NA NA
97.61681818 97.75363636 97.83368421 98.0605 98.23681818 98.30285714
NA NA NA NA NA NA
98.47315789 98.49142857 98.51947368 99.11181818 99.2847619 99.60045455
NA NA NA NA NA NA
99.82391304 100.2495238 100.7671429 101.1595 101.4008696 101.416087
NA NA NA NA NA NA
101.4672727 101.5138095 101.5305263 101.605 101.916087 101.96
NA NA NA NA NA NA
102.1347368 102.2484211 102.347 102.8890476 103.1942105 103.435
NA NA NA NA NA NA
103.456 103.4926087 103.9905 104.0086364 104.1977273 104.5781818
NA NA NA NA NA NA
104.7154545 104.7247619 104.7419048 104.7652381 105.093913 105.2465
NA NA NA NA NA NA
105.3921053 105.4022727 105.6934783 106.1972727 106.6704762 106.6747619
NA NA NA NA NA NA
106.7171429 106.8009091 107.3861905 107.4805 107.55 107.6085
NA NA NA NA NA NA
107.9415 108.2469565 108.3509091 108.362 109.4368182 109.85
NA NA NA NA NA NA
109.854 110.1840909 110.2704545 110.3104545 110.5161905 110.548
NA NA NA NA NA NA
110.6795455 111.0695238 111.1790909 111.1931579 111.211 111.26
NA NA NA NA NA NA
111.2733333 111.2986364 111.4091304 111.8159091 111.9713043 112.023
NA NA NA NA NA NA
112.2061905 112.2665 113.179 113.2061905 113.4490476 113.504
NA NA NA NA NA NA
113.5634783 113.8736364 113.8865 113.9954545 114.1172727 114.2457895
NA NA NA NA NA NA
114.2681818 114.5752381 114.6895238 114.9686364 115.3836364 115.491
NA NA NA NA NA NA
115.6943478 115.6985 115.7813636 115.886 115.9817391 116.3066667
NA NA NA NA NA NA
116.4833333 116.5263158 116.91 116.9995238 117.5085 117.5985714
NA NA NA NA NA NA
117.8508696 118.1286364 118.4309524 118.6233333 118.85 119.0454545
NA NA NA NA NA NA
119.0555 119.0557143 119.3071429 119.3190476 119.5143478 119.5490909
NA NA NA NA NA NA
119.8433333 120.3235 120.651 120.6855 120.755 120.91
NA NA NA NA NA NA
121.3004762 121.3290909 121.3485714 121.716087 122.1885 122.2395455
NA NA NA NA NA NA
123.2542105 123.3026087 123.367619 123.4077273 123.5804762 123.582381
NA NA NA NA NA NA
123.6819048 123.694 123.7419048 123.862 124.3526316 124.4472727
NA NA NA NA NA NA
124.6173913 124.9171429 124.9915 125.0914286 125.2735 125.4525
NA NA NA NA NA NA
125.5242857 125.6418182 125.8010526 126.1661905 126.2936364 126.8236364
NA NA NA NA NA NA
127.0756522 127.3256522 127.3605263 127.5942857 128.2138095 128.2559091
NA NA NA NA NA NA
128.4766667 128.8695455 128.8963636 130.0547619 130.1271429 131.0266667
NA NA NA NA NA NA
132.0278947 133.7590909 134.0673684 134.8709524 135.847 136.4689474
NA NA NA NA NA NA
136.5968182 138.3309091 138.3885714 139.3427273 141.6775 142.128
NA NA NA NA NA NA
145.3486364 146.5552632 148.5028571 148.7228571 149.4547619 149.6075
NA NA NA NA NA NA
150.7866667 151.0072727 153.4163636 156.2784211 156.532381 156.8585
NA NA NA NA NA NA
157.757619 157.9657143 159.4913636 161.6890909 162.2075 164.5027273
NA NA NA NA NA NA
168.1209524 168.1545455 168.4233333 169.394 172.4331818 173.2078947
NA NA NA NA NA NA
175.42 175.5769565 181.57 182.292381 184.5661905 186.3426316
NA NA NA NA NA NA
187.6228571 199.6254545 201.6036364 205.9304348 206.3586364 206.4747368
NA NA NA NA NA NA
210.9377273 211.1261905 213.932 213.9635 214.7038095 219.2863636
NA NA NA NA NA NA
219.62 220.019 221.7054545 231.042381 234.9278947 241.0014286
NA NA NA NA NA NA
241.1081818 242.5472727 244.1728571 247.357619 247.6765 252.0065
NA NA NA NA NA NA
252.5968182 252.9315 253.5547619 256.4795455 257.9542105 258.162381
NA NA NA NA NA NA
258.2178947 258.5552381 259.7073913 261.8880952 261.9538095 262.7677273
NA NA NA NA NA NA
263.2513636 265.0127273 265.12 265.2571429 265.376 266.6331579
NA NA NA NA NA NA
267.1147619 267.1505 267.205 268.0286957 269.9352381 270.1505
NA NA NA NA NA NA
270.3752381 271.7959091 272.3690476 272.3752632 274.5056522 274.7572727
NA NA NA NA NA NA
274.857619 274.9052381 277.2085714 278.4268182 278.4873684 280.86
NA NA NA NA NA NA
281.0014286 281.502 290.282 291.1530435 294.4663636 296.4255
NA NA NA NA NA NA
296.8752381 302.3977273 303.8478261 304.2442857 304.6547619 304.7578947
NA NA NA NA NA NA
305.4052381 308.825 309.3363636 309.6777273 312.3452381 313.6135
NA NA NA NA NA NA
314.5340909 316.4505 317.53 319.0290909 319.8527273 327.1818182
NA NA NA NA NA NA
327.3457143 333.8689474 343.325 346.7236842 350.6904762 351.9078261
NA NA NA NA NA NA
357.0538095 360.3190476 369.9315 378.08 384.238 388.625
NA NA NA NA NA NA
389.025 389.9204545 393.8754545 394.8468182 395.7631579 396.0125
NA NA NA NA NA NA
400.1375 413.7173913 423.725 424.5061905 437.4040909 438.9015789
NA NA NA NA NA NA
Repeat the tapply function from the previous problem for each of the other four companies, and use the output to answer the remaining questions.
General Electric and Coca-Cola both have their highest average stock price in the same month. Which month is this?
For the months of December and January, every company’s average stock is higher in one month and lower in the other. In which month are the stock prices lower?
After seeing these trends, we are ready to buy stock in certain months and sell it in others! But, we should be careful, because one really good or really bad year could skew the average to show a trend that is not really there in general.