简体   繁体   English

有什么方法可以将日期和时间数据存储在R中的数组中?

[英]Is there any way to store date and time data in an array in R?

I understand that data.frame is of dimension 2 and array is like a matrix in higher dimensions so its elements should of the same data type. 我知道data.frame是2维的,而array就像是更高维度的矩阵,因此它的元素应该是相同的数据类型。 I wonder if there is any class or solution to store data including both date and time and numeric values to a variable of dimension 3. Thank you for your help. 我想知道是否存在任何类或解决方案来将数据(包括日期和时间以及数字值)存储到维度3的变量中。谢谢您的帮助。

All elements in an array must be of the same data type. 数组中的所有元素必须具有相同的数据类型。 However; 然而; you can convert your date and time to "number of seconds since epoch" and use that since it is numeric. 您可以将日期和时间转换为“距纪元的秒数​​”,并使用数字形式的值。 For example how to convert the current time: 例如如何转换当前时间:

>st <- Sys.Time()
>print(st)
[1] "2018-03-30 23:55:56 CDT"
>print(as.numeric(st))
[1] 1522472156

A "POSIXct" vector such as x below can be given dimensions using dim<- "POSIXct"载体如x下面可以给出使用维dim<-

x <- Sys.time() + 1:8
dim(x) <- c(2, 2, 2)

class(x)
## [1] "POSIXct" "POSIXt" 

dim(x)
## [1] 2 2 2

It can alternately be written in this form: 也可以用以下形式编写:

x <- Sys.time() + 1:8
xx <- `dim<-`(x, c(2, 2, 2))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法在coreData中存储多维数组? - Is there any way to store a multidimensional array in coreData? 有没有办法将 null 值存储在整数数组中? - Is there any way to store a null value in an array of integers? 存储此数据的最佳方式(数组,对象等) - Best way to store this data (array, object, etc) 有没有办法将 firestore 中的数据值存储到数组中? - Is there a way to store data values from firestore into an array? 将数据从 MongoDB 存储到数组的更快方法 - Faster way to store data from MongoDB into array 有没有办法将文件中存在的元素存储到 java 中的 object 的数组中 - Is there any way to store the elements present in the file to the to the array of the object in java 有什么方法可以将2D阵列存储在持久性存储中吗? - Is there any way to store a 2D array in a persistant storage? 使用R中的for循环将时间序列函数的值存储在数组中 - Store values from a time series function in an array using a for loop in R 将数组中的时间数据与 reactJS 中的当前日期进行比较 - Compare the time data in an array with current date in reactJS 用php中的合并日期和时间对数组数据进行排序 - Sorting array data with a combine date and time in php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM