我尝试使用此代码通过 read.zoo 读取多个 CSV 文件,但我遇到了问题。方向不同,所以我用file.path()
. 问题是:原始文件中的 Date.Time 有 Date format= "%m/%d %HH:%MM:%SS"
,我需要在函数"%Y/"
之前或内部添加read.zoo()
。我怎么能这样做?我尝试使用子函数,但我需要一个参数。哪一个?是否有可能绕过这个问题?
library(zoo)
for(i in Dir1){
filepath <- file.path(paste(i,".csv",sep=""))
#f<-function(x) sub("([[:print:]]{15})$", "2005/\\1",x)
dat<-read.zoo(filepath,header=TRUE,sep=",",
FUN = function(x) sub("([[:print:]]{15})$", "2005/\\1"))
filenames <- substr(filepath,122,155)
names <-substr(filenames,1,21)
assign(names, dat)
}
Some of my data:
Date.time,Outdoor Dry Bulb [C],Outdoor Relative Humidity [%],Air Temperature [C],Surface Temperature [C]
01/01 00:03:00,0.0,50.,23.,16.3588068633603
01/01 00:06:00,0.0,50.,23.,16.1696661072302
01/01 00:09:00,0.0,50.,23.,13.8864861630478
01/01 00:12:00,0.0,50.,23.,13.006618496734
01/01 00:15:00,0.0,50.,23.,12.5542552024807
01/01 00:18:00,0.0,50.,23.,11.6201669301972