[R] 回复: high-frequency data in R
Daniel Nordlund
djnord|und @end|ng |rom gm@||@com
Tue Nov 24 22:02:19 CET 2020
On 11/24/2020 12:20 PM, Zixuan Qi wrote:
> DATE SYMBOL price permno
> 10/1/2019 9:30 AA 93.26 24109
> 10/1/2019 9:31 AA 93.44 24109
> 10/1/2019 9:32 AA 93.44 24109
> 10/1/2019 9:33 AA 93.28 24109
> 10/1/2019 9:34 AA 93.37 24109
> 10/1/2019 9:35 AA 93.37 24109
> 10/1/2019 9:36 AA 93.33 24109
> 10/1/2019 9:30 AA 114.47 10138
> 10/1/2019 9:32 AA 114.22 10138
> 10/1/2019 9:33 AA 114.26 10138
> 10/1/2019 9:34 AA 114.27 10138
> 10/1/2019 9:35 AA 114.01 10138
> 10/1/2019 9:36 AA 114.07 10138
> 10/1/2019 9:37 AA 114.39 10138
> 10/1/2019 9:38 AA 114.32 10138
> The sample data is here.
> ________________________________
> ������: Zixuan Qi
> ����ʱ��: 2020��11��25�� 4:12
> �ռ���: r-help using r-project.org <r-help using r-project.org>
> ����: high-frequency data in R
>
> Hello,
>
> I attach the sample data in the email and you can use the data to try my code.
> My code is as follow.
>
> library('highfrequency')
> library('xts')
> data=read.table("sample data.csv",header=F,skip = 1,stringsAsFactors=FALSE,sep="\t")
> colnames(data)=c(" ",'SYMBOL',"PRICE","PERMNO")
> id <- unique(data$PERMNO)
> mydata <- data.frame()
> for (i in id){
> tmp <-data[data$PERMNO==i,]
> row.names(tmp)=tmp[,1]
> tmp=tmp[,-1]
> tmp.xts <- as.xts(tmp, order.by=as.POSIXlt(rownames(tmp),format="%Y/%m/%d %H:%M"))
> mydata <- rbind(mydata,tmp.xts)
> }
>
> The problem is that when I try to program tmp.xts <- as.xts(tmp, order.by=as.POSIXlt(rownames(tmp),format="%Y/%m/%d %H:%M")), then I get NaN rownames. I don't know why.
>
> Thanks very much.
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
You have the wrong format for your date conversion. It should be
format="%m/%d/%Y %H:%M"
Hope this is helpful,
Dan
--
Daniel Nordlund
Port Townsend, WA USA
More information about the R-help
mailing list