Created
September 20, 2015 04:54
-
-
Save YushengLi/d692f5ac042901ddaf00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# install.packages("RCurl") | |
library(RCurl) | |
URL <- "http://www.twse.com.tw/ch/trading/fund/BFI82U/BFI82U_print.php?begin_date=20150918&end_date=20150918&report_type=day&language=ch&save=csv" | |
# Download data from URL and set encoding to Big5 | |
rawData <- getURL(URL, .encoding='big5') | |
# Convert Encoding from Big5 to UTF-8 | |
rawData <- iconv(rawData, 'big5', 'utf8') | |
# Remove unnecessary Title by parsing data to Vector | |
rawData <- readLines(textConnection(rawData))[-1] | |
# Parsing data back to text | |
rawData <- rawData[1:length(rawData)] | |
# Read table from parsedText | |
parsedData = read.table(textConnection(rawData), sep=',', header = T) | |
# parsedData = read.table(textConnection(rawData), sep=',', skip = 1, header = T) | |
# Convert Text to Numeric by removing `,` with gsub and using as.numeric | |
coltocvt <- 2:4 | |
parsedData[,coltocvt] <- lapply(parsedData[,coltocvt], function(x) {as.numeric(gsub(',', '', x))}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment