我将时间序列日期作为数据框加载到 R 中。但是,当我查看数据时,时间序列日期不会显示为字符串,尽管日期列的类被识别为日期类。如果不使用动物园,我怎样才能让数据集以字符串格式显示日期。这实际上是出于视觉目的,以便能够查看数据是否正确。
Date Open High Low Close Volume Adj Close
3/8/2013 834.5 834.92 825.05 831.52 2911900 831.52
3/7/2013 834.06 836.62 829.58 832.6 2052700 832.6
3/6/2013 841.03 844 828.81 831.38 2873000 831.38
3/5/2013 828.93 840.15 828.9 838.6 4044100 838.6
3/4/2013 805.3 822.84 805 821.5 2775600 821.5
在 R 中显示为:
Date Open High Low Close Volume Adj.Close
15772 834.50 834.92 825.05 831.52 2911900 831.52
15771 834.06 836.62 829.58 832.60 2052700 832.60
15770 841.03 844.00 828.81 831.38 2873000 831.38
15769 828.93 840.15 828.90 838.60 4044100 838.60
15768 805.30 822.84 805.00 821.50 2775600 821.50
15765 797.80 807.14 796.15 806.19 2175400 806.19
我正在使用命令
data=read.csv("file location",header=T,colClasses=c("Date","numeric","numeric","numeric","numeric","numeric","numeric"))
这是输入输出:
dput(head(data))
structure(list(Date = structure(c(15772, 15771, 15770, 15769,
15768, 15765), class = "Date"), Open = c(834.5, 834.06, 841.03,
828.93, 805.3, 797.8), High = c(834.92, 836.62, 844, 840.15,
822.84, 807.14), Low = c(825.05, 829.58, 828.81, 828.9, 805,
796.15), Close = c(831.52, 832.6, 831.38, 838.6, 821.5, 806.19
), Volume = c(2911900, 2052700, 2873000, 4044100, 2775600, 2175400
), Adj.Close = c(831.52, 832.6, 831.38, 838.6, 821.5, 806.19)), .Names = c("Date",
"Open", "High", "Low", "Close", "Volume", "Adj.Close"), row.names = c(NA,
6L), class = "data.frame")