我正在使用 Data <- read.table("file", head=TRUE, sep=";")
来读取我的文件。
我的文件的 head
看起来像这样:
Date Time Global_active_power Global_reactive_power Voltage Global_intensity
66637 2007-02-01 00:00:00 0.326 0.128 243.150 1.400
66638 2007-02-01 00:01:00 0.326 0.130 243.320 1.400
66639 2007-02-01 00:02:00 0.324 0.132 243.510 1.400
66640 2007-02-01 00:03:00 0.324 0.134 243.900 1.400
66641 2007-02-01 00:04:00 0.322 0.130 243.160 1.400
66642 2007-02-01 00:05:00 0.320 0.126 242.290 1.400
Sub_metering_1 Sub_metering_2 Sub_metering_3
66637 0.000 0.000 0
66638 0.000 0.000 0
66639 0.000 0.000 0
66640 0.000 0.000 0
66641 0.000 0.000 0
66642 0.000 0.000 0
然而,如果我尝试使用typeof(Data$Global_reactive_power)
,它会显示integer
(应该是numeric
)。
我不明白为什么会出现这种情况。我尝试了很多方法,但似乎都没有起作用,有人能帮我吗?
我的文件在这里: https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip
Data$Global_reactive_power <- as.numeric(Data$Global_reactive_power)
,或者在调用read.table
时手动指定每列的类别。请参阅read.table
的帮助文件中的colClasses
参数 (?read.table
)。 - nrussell