[R-SIG-Finance] How to remove the error : Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent

Jeff Ryan jeff.a.ryan at gmail.com
Tue Jun 24 00:09:34 CEST 2008


The issue lies in the data format, this time your time column has both
date _AND_ time in it.  So you need to adjust the xts conversion as
well:

> x <- xts(as.matrix(quotes[,-1]),as.POSIXct(paste(quotes[,1]),format='%m/%d/%Y %H:%M'))

> colnames(x) <- c('Open','High','Low','Close','Volume')

> x
                       Open    High     Low   Close Volume
2007-01-08 00:59:00 1.93025 1.93035 1.92930 1.92960    -60
2007-01-08 01:59:00 1.92960 1.93010 1.92625 1.92805    -60
2007-01-08 02:59:00 1.92805 1.92970 1.92770 1.92780    -60
2007-01-08 03:59:00 1.92780 1.92835 1.92720 1.92825    -60
2007-01-08 04:59:00 1.92825 1.92960 1.92825 1.92900    -60
2007-01-08 05:59:00 1.92900 1.92925 1.92865 1.92925    -60
2007-01-08 06:59:00 1.92925 1.93085 1.92870 1.93065    -60
2007-01-08 07:59:00 1.93065 1.93310 1.93025 1.93300    -60
2007-01-08 08:59:00 1.93300 1.93435 1.93105 1.93110    -60
2007-01-08 09:59:00 1.93110 1.93475 1.93035 1.93400    -60
2007-01-08 10:59:00 1.93400 1.93465 1.93230 1.93240    -60
2007-01-08 11:59:00 1.93240 1.93350 1.93120 1.93305    -60
2007-01-08 12:59:00 1.93305 1.93385 1.93210 1.93360    -60
2007-01-08 13:59:00 1.93360 1.93375 1.93240 1.93345    -60
2007-01-08 14:59:00 1.93345 1.93360 1.92865 1.92905    -60
2007-01-08 15:59:00 1.92905 1.93460 1.92825 1.93410    -60
2007-01-08 16:59:00 1.93410 1.93735 1.93400 1.93465    -60
2007-01-08 17:59:00 1.93465 1.93865 1.93405 1.93840    -60
2007-01-08 18:59:00 1.93840 1.94050 1.93715 1.93775    -60
2007-01-08 19:59:00 1.93775 1.93935 1.93730 1.93730    -60
2007-01-08 20:59:00 1.93730 1.93870 1.93615 1.93780    -60
2007-01-08 21:59:00 1.93780 1.93840 1.93770 1.93780    -60
2007-01-08 22:59:00 1.93780 1.93815 1.93740 1.93780    -60
2007-01-08 23:58:00 1.93815 1.93925 1.93815 1.93905    -44

> barChart(x,TA=NULL)

Jeff


On Mon, Jun 23, 2008 at 4:38 PM,  <pierre8r-list at yahoo.fr> wrote:
> Hello,
>
>
> The errors from the console :
>
>> colnames(x) <- c('Open','High','Low','Close','Volume')
> Error in dimnames(x) <- dn :
>  length of 'dimnames' [2] not equal to array extent
>
>
>
> The complete script :
>
> library(xts)
> library(quantmod)
> quotes <- read.csv2("K:\\00001-Compare\\Output\\OutputJBacktesting\\Quotes1HOUR.txt", header = FALSE, sep = ",", dec=".")
> x <- xts(as.matrix(quotes[,-(1:2)]),as.POSIXct(paste(quotes[,1],quotes[,2]),format='%m/%d/%Y
> %H:%M'))
>
> colnames(x) <- c('Open','High','Low','Close','Volume')
>
> barChart(x,TA=NULL)
>
>
> Thanks,
>
> Pierre8r
>
> Some datas :
>
> 01/08/2007 00:59:00,1.930250,1.930350,1.929300,1.929600,-60
> 01/08/2007 01:59:00,1.929600,1.930100,1.926250,1.928050,-60
> 01/08/2007 02:59:00,1.928050,1.929700,1.927700,1.927800,-60
> 01/08/2007 03:59:00,1.927800,1.928350,1.927200,1.928250,-60
> 01/08/2007 04:59:00,1.928250,1.929600,1.928250,1.929000,-60
> 01/08/2007 05:59:00,1.929000,1.929250,1.928650,1.929250,-60
> 01/08/2007 06:59:00,1.929250,1.930850,1.928700,1.930650,-60
> 01/08/2007 07:59:00,1.930650,1.933100,1.930250,1.933000,-60
> 01/08/2007 08:59:00,1.933000,1.934350,1.931050,1.931100,-60
> 01/08/2007 09:59:00,1.931100,1.934750,1.930350,1.934000,-60
> 01/08/2007 10:59:00,1.934000,1.934650,1.932300,1.932400,-60
> 01/08/2007 11:59:00,1.932400,1.933500,1.931200,1.933050,-60
> 01/08/2007 12:59:00,1.933050,1.933850,1.932100,1.933600,-60
> 01/08/2007 13:59:00,1.933600,1.933750,1.932400,1.933450,-60
> 01/08/2007 14:59:00,1.933450,1.933600,1.928650,1.929050,-60
> 01/08/2007 15:59:00,1.929050,1.934600,1.928250,1.934100,-60
> 01/08/2007 16:59:00,1.934100,1.937350,1.934000,1.934650,-60
> 01/08/2007 17:59:00,1.934650,1.938650,1.934050,1.938400,-60
> 01/08/2007 18:59:00,1.938400,1.940500,1.937150,1.937750,-60
> 01/08/2007 19:59:00,1.937750,1.939350,1.937300,1.937300,-60
> 01/08/2007 20:59:00,1.937300,1.938700,1.936150,1.937800,-60
> 01/08/2007 21:59:00,1.937800,1.938400,1.937700,1.937800,-60
> 01/08/2007 22:59:00,1.937800,1.938150,1.937400,1.937800,-60
> 01/08/2007 23:58:00,1.938150,1.939250,1.938150,1.939050,-44
>
>
>
>
>
>      ____________________________________________________________
> ente http://mail.yahoo.fr
>
> _______________________________________________
> R-SIG-Finance at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only.
> -- If you want to post, subscribe first.
>



-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



More information about the R-SIG-Finance mailing list