将R数据帧转换为时间序列

时间:2019-03-16 19:18:04

标签: r xts

您好,我一直在尝试使用xts将数据帧转换为时间序列,我的理解是,我需要先将当前设置了字符类型的Date列转换为我的数据集具有约250行的日期类型,我希望访问包含日期数据的列,然后运行将char转换为日期的函数。任何建议都将对您有所帮助。

str(gas)
Classes ‘spec_tbl_df’, ‘tbl_df’, ‘tbl’ and 'data.frame':    253 obs. of     
5 variables:
$ Date         : chr  "8/22/2017" "8/23/2017" "8/24/2017" "8/25/2017" ...
$ Google.Close : num  925 927 921 916 914 ...
$ Amazon.Close : num  967 958 952 945 946 ...
$ Google.Return: num  NA 0.0025 -0.00617 -0.00585 -0.00227 ...
$ Amazon.Return: num  NA -0.009205 -0.005793 -0.007549 0.000804 ...
 - attr(*, "spec")=
 .. cols(
 ..   Date = col_character(),
 ..   Google.Close = col_double(),
 ..   Amazon.Close = col_double(),
 ..   Google.Return = col_double(),
 ..   Amazon.Return = col_double()
 .. )

1 个答案:

答案 0 :(得分:0)

您可以使用const validation = require('../middleware/validation.js'); const { check } = require('express-validator/check'); router.get('/', topicsController.getAllTopics); router.get('/:topicId', [ check('topicId').isUUID() ], validation, topicsController.getTopicById); router.post('/', authenticationCheck, authorizationCheck, [ check('parentTopicId').isUUID() || check('parentTopicId').isNull(), // check if it's a UUID. If not, check if it's null !check('name').isEmpty(), // is it not empty? ], validation, topicsController.createTopic); router.put('/:topicId', authenticationCheck, authorizationCheck, [ check('topicId').isUUID(), check('parentTopicId').isUUID() || check('parentTopicId').isNull(), !check('name').isEmpty(), ], validation, topicsController.updateTopic); router.delete('/:topicId', authenticationCheck, authorizationCheck, [ check('topicId').isUUID() ], validation, topicsController.deleteTopic); 函数。您将需要指定日期的格式。您的情况似乎是as.Date。您可以在帮助页面%m/%d/%Y中了解这些格式。

?strptime