我使用zoo
包中的R,分析時間序列數據的因素默認情況下。我有以下數據文件:停止數據被讀取作爲與read.zoo
Date(dd-mm-yy),Time(hh:mm:ss),Julian_Day,AOT_1640,AOT_1020,AOT_870,AOT_675,AOT_667,AOT_555,AOT_551,AOT_532,AOT_531,AOT_500,AOT_490,AOT_443,AOT_440,AOT_412,AOT_380,AOT_340,Water(cm),%TripletVar_1640,%TripletVar_1020,%TripletVar_870,%TripletVar_675,%TripletVar_667,%TripletVar_555,%TripletVar_551,%TripletVar_532,%TripletVar_531,%TripletVar_500,%TripletVar_490,%TripletVar_443,%TripletVar_440,%TripletVar_412,%TripletVar_380,%TripletVar_340,%WaterError,440-870Angstrom,380-500Angstrom,440-675Angstrom,500-870Angstrom,340-440Angstrom,440-675Angstrom(Polar),Last_Processing_Date(dd/mm/yyyy),Solar_Zenith_Angle
29:03:2011,09:26:28,88.393380,N/A,0.490230,0.553836,0.707512,N/A,N/A,N/A,N/A,N/A,0.911939,N/A,N/A,0.984430,N/A,1.046517,1.081283,1.632430,N/A,4.597345,4.551429,3.216097,N/A,N/A,N/A,N/A,N/A,2.587552,N/A,N/A,2.694179,N/A,2.085042,2.522511,2.309844,0.851964,0.497006,0.789257,0.898093,0.362423,N/A,13/04/2011,58.822462
29:03:2011,09:41:28,88.403796,N/A,0.440362,0.513093,0.676703,N/A,N/A,N/A,N/A,N/A,0.893867,N/A,N/A,0.965588,N/A,1.034943,1.079975,1.654521,N/A,12.867837,12.687550,11.037238,N/A,N/A,N/A,N/A,N/A,9.345739,N/A,N/A,8.423888,N/A,8.421787,9.334135,1.622026,0.937815,0.529939,0.852553,0.999260,0.431102,N/A,13/04/2011,57.070624
29:03:2011,10:11:29,88.424641,N/A,0.565148,0.654724,0.842142,N/A,N/A,N/A,N/A,N/A,1.070556,N/A,N/A,1.144966,N/A,1.208759,1.242663,1.666760,N/A,9.933505,9.499251,8.327355,N/A,N/A,N/A,N/A,N/A,6.781617,N/A,N/A,6.612952,N/A,5.600500,5.630695,1.302058,0.826713,0.438445,0.736362,0.884554,0.316539,N/A,13/04/2011,53.916620
29:03:2011,10:17:46,88.429005,N/A,0.593881,0.681572,0.866620,N/A,N/A,N/A,N/A,N/A,1.095508,N/A,N/A,1.168008,N/A,1.233022,1.268572,1.704882,N/A,4.072782,3.752197,3.210935,N/A,N/A,N/A,N/A,N/A,2.389567,N/A,N/A,2.385582,N/A,1.653326,1.015620,0.728711,0.798185,0.427272,0.716165,0.853963,0.319100,N/A,13/04/2011,53.323057
29:03:2011,10:26:27,88.435035,N/A,0.636627,0.714175,0.884887,N/A,N/A,N/A,N/A,N/A,1.092220,N/A,N/A,1.167024,N/A,1.224264,1.271774,1.626393,N/A,16.400200,10.585139,6.513873,N/A,N/A,N/A,N/A,N/A,3.169704,N/A,N/A,4.085949,N/A,3.963741,8.663229,10.035231,0.724581,0.411533,0.659996,0.764539,0.329073,N/A,13/04/2011,52.544475
我嘗試使用下面的代碼來閱讀:
f <- function(d, t) as.chron(paste(as.Date(chron(d, format='d:m:y')), t))
z = read.zoo("110329_110329_Chilbolton.lev10", sep=',', header=T, index = 1:2, FUN=f, as.is=F, dec=".")
但所有的數據集的列都被解讀爲因素 - 所以,當我做summary(z)
我得到的輸出,如:
X.TripletVar_340 X.WaterError X440.870Angstrom X380.500Angstrom X440.675Angstrom X500.870Angstrom
1.015620:1 0.728711:1 0.724581:1 0.411533:1 0.659996:1 0.764539:1
2.522511:1 1.302058:1 0.798185:1 0.427272:1 0.716165:1 0.853963:1
5.630695:1 1.622026:1 0.826713:1 0.438445:1 0.736362:1 0.884554:1
8.663229:1 2.309844:1 0.851964:1 0.497006:1 0.789257:1 0.898093:1
9.334135:1 10.035231:1 0.937815:1 0.529939:1 0.852553:1 0.999260:1
我怎麼能阻止它讀取數據爲默認的因素?該數據由read.table
沒有任何額外的參數讀取罰款告訴它,以確保一切保持原樣不編號的因素 - 那麼爲什麼read.zoo
表現不同?
我想我可以使用colClasses來指定每列的類型,但我寧願不這樣做,以防數據集中列的順序發生變化 - 默認情況下將其轉換爲數字,然後嘗試因素如果不起作用會好得多。
任何想法?
+1請注意,我堅信,TRUE; /'FALSE'應始終以長格式寫的。這很容易聲明一個名爲F的變量,然後可能會導致各種意想不到的事情,其中你寫'F'爲'FALSE' – Andrie
感謝您的建議,但似乎沒有工作,我仍然得到所有的數字輸出作爲因素(與上面的輸出沒有差別)。任何其他想法? – robintw
Arg ...對不起羅賓。我無法確定,因爲你的代碼不適合我。我想我錯過了'as.chron'功能。讓我跟蹤它,看看... –