Reading a non-standard CSV File into R -
im trying read following csv file r
http://asic.gov.au/reports/ytd/2015/rr20150511-001-ssdailyytd.csv
the code im using is:
url <- "http://asic.gov.au/reports/ytd/2015/rr20150511-001-ssdailyytd.csv" shorthistory <- read.csv(url, skip = 4)
however keep getting following error.
1: in readlines(file, skip) : line 1 appears contain embedded nul
2: in readlines(file, skip) : line 2 appears contain embedded nul
3: in readlines(file, skip) : line 3 appears contain embedded nul
4: in readlines(file, skip) : line 4 appears contain embedded nul
which leads me believe utilizing function incorrectly failing every line.
any appreciated!
due blank @ top left corners, read.csv()
doesn't seem work. file has read line line (readlines()
) followed skipping the first 4 lines.
below shows example. file open file connection (file()
) , read line line (readlines()
). first 4 lines skipped subsetting. file tab-delimited strsplit()
applied recursively. still kept string lists , should reformatted data frame or other suitable types.
# open file connection , read lines path <- "http://asic.gov.au/reports/ytd/2015/rr20150511-001-ssdailyytd.csv" con <- file(path, open = "rt", raw = true) text <- readlines(con, skipnul = true) close(con) # skip first 4 lines text <- text[5:length(text)] # recursively split string text <- do.call(c, lapply(text, strsplit, split = "\t")) text[[1]][1:4] # [1] "1-page ltd ordinary" "1pg " "1330487" "1.72"
Comments
Post a Comment