r - "Index has bad entries at data rows" error when reading CSV -


i have .csv file containing stock prices in below format

date    open    high    low close 3/7/2014 10:15  228.28  236.58  228.23  236.18 3/7/2014 11:15  236.23  241.27  236.09  241.14 3/7/2014 12:15  241.1   246.12  241.1   242.96 3/7/2014 13:15  242.84  243.92  242     242.32 

when running below script:

test <- as.xts(read.zoo(mytest.csv', header=t, fill=t, index.column = 1, row.names=null,stringsasfactors = false, sep="",format="%m/%d/%y %h:%m", tz="")) 

the below error shown

error in read.zoo("mydata.csv", header = t, fill = t, index.column = 1, : index has bad entries @ data rows:1 2 3 4 5 6 7 8

i'm not sure as.xts function see 2 small fixes need data r.

first should add variable name time since read.zoo function uses same delimiter read.table if want work header need name each column.

date     time   open    high    low     close 3/7/2014 10:15  228.28  236.58  228.23  236.18 3/7/2014 11:15  236.23  241.27  236.09  241.14 3/7/2014 12:15  241.1   246.12  241.1   242.96 3/7/2014 13:15  242.84  243.92  242     242.32 

second, can read in file above follows

library(zoo) indata <- read.zoo("mydata.csv", header=true, index.column = 1:2, format="%m/%d/%y %h:%m", tz="cet") 

note 2 indices given since date/time split on 2 columns. also, think tz needed date/time conversion work. in case above gives

> indata                       open   high    low  close 2014-03-07 10:15:00 228.28 236.58 228.23 236.18 2014-03-07 11:15:00 236.23 241.27 236.09 241.14 2014-03-07 12:15:00 241.10 246.12 241.10 242.96 2014-03-07 13:15:00 242.84 243.92 242.00 242.32 

which can passed other r functions.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -