[R] xts and data.frame question

devol sunduck at gmail.com
Tue Sep 15 11:12:17 CEST 2009


Hello there!

 does any one know how to convert the following type of data

> z
           DATE     TIME     ISIN  PRICE VOL  ID_DEAL RANK
1881 2009-09-11 10:30:59 RTS-9.09 117445  10 98200801    1
1882 2009-09-11 10:31:59 RTS-9.09 117450   1 98202144    6
1883 2009-09-11 10:32:59 RTS-9.09 117285   1 98203075    1
1884 2009-09-11 10:33:59 RTS-9.09 117180   3 98203828    1
1885 2009-09-11 10:34:58 RTS-9.09 117155   6 98204485    1
> str(z)
'data.frame':   5 obs. of  7 variables:
 $ DATE   : Factor w/ 1 level "2009-09-11": 1 1 1 1 1
 $ TIME   : Factor w/ 3331 levels "10:30:05","10:30:14",..: 8 15 23 30 38
 $ ISIN   : Factor w/ 25 levels "BR-9.09","CHMF-9.09",..: 15 15 15 15 15
 $ PRICE  : num  117445 117450 117285 117180 117155
 $ VOL    : num  10 1 1 3 6
 $ ID_DEAL: int  98200801 98202144 98203075 98203828 98204485
 $ RANK   : int  1 6 1 1 1
> 

to xts object without any modifications to data types of columns... namely,
when I try to convert by means of

> z<-as.xts(z[,3:6],order.by=as.POSIXct(paste(z$DATE,z$TIME)))
> z
                    ISIN       PRICE    VOL  ID_DEAL   
2009-09-11 10:30:59 "RTS-9.09" "117445" "10" "98200801"
2009-09-11 10:31:59 "RTS-9.09" "117450" " 1" "98202144"
2009-09-11 10:32:59 "RTS-9.09" "117285" " 1" "98203075"
2009-09-11 10:33:59 "RTS-9.09" "117180" " 3" "98203828"
2009-09-11 10:34:58 "RTS-9.09" "117155" " 6" "98204485"
> str(z)
An ‘xts’ object from 2009-09-11 10:30:59 to 2009-09-11 10:34:58 containing:
  Data: chr [1:5, 1:4] "RTS-9.09" "RTS-9.09" "RTS-9.09" "RTS-9.09"
"RTS-9.09" "117445" ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:4] "ISIN" "PRICE" "VOL" "ID_DEAL"
  Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT
  Original class: 'data.frame'  
  xts Attributes:  
 NULL
> 

I get PRICE and VOL columns converted to Char type of data, but I want it to
be in numeric format - are there any ways to do it? I tried to convert the
original columns by as.numeric but in any case xts converts it to char... 

Thanks in advance!
-- 
View this message in context: http://www.nabble.com/xts-and-data.frame-question-tp25450688p25450688.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list