Skip to content

Commit

Permalink
Fix stringsAsFactors problem with lubridate
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmyleswhite committed Jul 31, 2013
1 parent 46ba2a8 commit 81e061e
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions 08-PCA/chapter08.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
library('ggplot2')

# First code snippet
prices <- read.csv(file.path('data', 'stock_prices.csv'))
prices <- read.csv(file.path('data', 'stock_prices.csv'),
stringsAsFactors = FALSE)

prices[1, ]
# Date Stock Close
Expand All @@ -43,7 +44,7 @@ prices <- subset(prices, Stock != 'DDR')
date.stock.matrix <- cast(prices, Date ~ Stock, value = 'Close')

# Fifth code snippet
cor.matrix <- cor(date.stock.matrix[,2:ncol(date.stock.matrix)])
cor.matrix <- cor(date.stock.matrix[, 2:ncol(date.stock.matrix)])
correlations <- as.numeric(cor.matrix)

ggplot(data.frame(Correlation = correlations),
Expand All @@ -52,7 +53,7 @@ ggplot(data.frame(Correlation = correlations),
theme(legend.position = 'none')

# Sixth code snippet
pca <- princomp(date.stock.matrix[,2:ncol(date.stock.matrix)])
pca <- princomp(date.stock.matrix[, 2:ncol(date.stock.matrix)])

# Seventh code snippet
#Call:
Expand Down Expand Up @@ -83,7 +84,8 @@ ggplot(data.frame(Loading = loadings),
market.index <- predict(pca)[, 1]

# Eleventh code snippet
dji.prices <- read.csv(file.path('data', 'DJI.csv'))
dji.prices <- read.csv(file.path('data', 'DJI.csv'),
stringsAsFactors = FALSE)
dji.prices <- transform(dji.prices, Date = ymd(Date))

# Twelfth code snippet
Expand Down

0 comments on commit 81e061e

Please sign in to comment.