-1
我試圖分析降雨量數據。但我的問題是,我有格式的數據:降雨量數據,無法獲得表格的價值?
head(dati)
X X.1 X.2 X.3 1. stat 2. stat 3.stat 4. stat 5. stat
2 2013 1 Val01 00:00 0 0.7 0.2
3 2013 1 Val01 01:00 0 0.5 0.2
4 2013 1 Val01 02:00 0 0 0.2
5 2013 1 Val01 03:00 0 0 0
6 2013 1 Val01 04:00 0 0 0.1
7 2013 1 Val01 05:00 0 0 0
正如你看到有在列的一些空間,當我試圖讓dati[1,5]
我得到
[1] 0.7
53 Levels: 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 ... HPRAB
我明白,我需要得到只有一個數字:0.7。我該怎麼做,爲什麼有關於關卡的信息?
我的代碼是:
dati<-read.csv2("precipitation.csv", header = TRUE,row.names=NULL,
sep = ";", quote = "", dec = "," , fill = TRUE, comment.char = "")
attach(dati)
dati[1,1]
[1] 2013
> dati[1,6]
[1] 0.7
53 Levels: 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 ... HPRAB
> dati[1,3]
[1] Val01
32 Levels: Val01 Val02 Val03 Val04 Val05 Val06 Val07 Val08 Val09 Val10 Val11 Val12 ... Val31
> dati[1,4]
[1] 00:00
25 Levels: 00:00 01:00 02:00 03:00 04:00 05:00 06:00 07:00 08:00 09:00 10:00 11:00 ... 23:00
>
解決!下一個代碼正常工作!
dati<-read.csv2("precipitation.csv", header = TRUE,row.names=NULL,
sep = ";", quote = "", dec = "," , fill = TRUE, comment.char = "")
attach(dati)
as.numeric(as.character(dati[1,i]))
我用'as.numeric(as.character(dati [1,i]))'這是工作! – user3642191