1

seems simple enough and I've been through all similar questions and applied them all... I'm either getting nothing or everything...

Trying to took at water temperatures (WTEMP) for specific date range(SAMPLE_DATE) 2007-06-01 to 2007-09-30 from (allconmon)

here is my code so far...

bydate<-subset(allconmon, allconmon$SAMPLE_DATE > as.Date("2007-06-01") & allconmon$SAMPLE_DATE < as.Date("2007-09-30"))

Ive also tried this but get errors

bydate2<- as.xts(allconmon$WTEMP,order.by=allconmon$SAMPLE_DATE)

 bydate2['2007-06-01/2007-09-30']

Error in xts(x, order.by = order.by, frequency = frequency, .CLASS = "double",  : 
  order.by requires an appropriate time-based object

not sure what I'm doing wrong here... seems to work for other people

4

2 回答 2

0

我想到了!在多个级别上...首先,当我从文本文件上传时,我没有注意到 R 对我的示例日期标签做了一些时髦的事情...可能是我的错...

这是数据集的一个小样本。它对 30 个变量的 5,573,301 个观测值

注意样本日期前面的时髦符号......不知道为什么 R 这样做......

 ï..SAMPLE_DATE SampleTime STATION SONDE Layer TOTAL_DEPTH TOTAL_DEPTH_A BATT BATT_A     WTEMP WTEMP_A SPCOND SPCOND_A SALINITY SALINITY_A DO_SAT DO_SAT_A

但是我做了什么......(我把名字改成了 x 因为 allconmon 有点过分了)

x <- read.csv(file = "C:/Users/Desktop/cmon2001-08.txt",quote = "",header = TRUE,sep = "\t", na.strings = c("","NULL"))

library(chron)

x$month <- months(as.Date(x$ï..SAMPLE_DATE, "%Y-%m-%d"))

x$year <- substr(as.character(x$ï..SAMPLE_DATE), 1, 4)

 y <- x[x$month == 'June' | x$month == 'July' | x$month == 'August' | x$month == 'September' ,]

所以现在我可以按这 4 个月对所有数据进行子集化,然后按年、站和水温进行子集化......

于 2013-11-14T14:21:39.853 回答
0

我强烈建议您zoo在处理时间序列数据时在 R 中使用包。

您提到的操作实际上windowzoo. 这是来自的示例?window

Examples

window(presidents, 1960, c(1969,4)) # values in the 1960's
window(presidents, deltat = 1)  # All Qtr1s
window(presidents, start = c(1945,3), deltat = 1)  # All Qtr3s
window(presidents, 1944, c(1979,2), extend = TRUE)

pres <- window(presidents, 1945, c(1949,4)) # values in the 1940's
window(pres, 1945.25, 1945.50) <- c(60, 70)
window(pres, 1944, 1944.75) <- 0 # will generate a warning
window(pres, c(1945,4), c(1949,4), frequency = 1) <- 85:89
pres

这是来自 JSS的论文列表,zoo展示了该包的使用也重塑了您的数据,我发现这非常鼓舞人心。

于 2013-11-13T16:25:41.183 回答