写一个R函数,要求如下
1. Data file (objective : to simplify the data import/export )
write a function to read data files with the following inputs
a. the number of data files (i.e. 3)
b. data file name & location (i.e. "c:\datadir\datafilename1"
"...datafilename2" " .... "3)
c. it shall be able to store date and time data types
d. it shall replace with a "0" if there is no data
e. it shall be able to export selected column / row to a csv file
下面是我写的程序,还不能很好的完成上面的功能,请高手指点
task1=function(n,f){
#输入f的格式f=c("C:\\Users\\Aimee\\Desktop\\R_job\\tt_mb_20071003\\tt1.txt","C:\\Users\\Aimee\\Desktop\\R_job\\tt_mb_20071003\\tt1.txt")
if(length(f)!=n) stop("Pls check the value of n or input the f again")
else{
task11=function(b){
t1=read.fwf(b,widths=c(5,9,8,11,1,2,2,2,4,2,2,2))
t1[is.na(t1)]=0
time=ISOdatetime(t1[,9],t1[,10],t1[,11],t1[,6],t1[,7],t1[,8])
data.frame(t1[,1],t1[,2],t1[,3],t1[,4],t1[,5],time,t1[,12])
}
#上面的task11执行的还可以,可是下面是不是不能这样存贮? 应该怎么处理最好呢?
#e的功能也还没完成,应该用sink函数吧?
for(i in 1:n){
x=task11(f[1])
ff=as.list(rep(x,n))
ff[]=task11(f)
}
}
}
恳请高手指点方向,谢谢!!!
下面是读取的数据的格式,tt1和tt2都是类似这样的数据
00001 2155010 126.500 1000A15475220071003 0
00001 2155010 126.500 1000A15475220071003 0
00001 2155010 126.500 2000A15472220071003 0
00001 2155010 126.500 2000A15475220071003 0
00001 2155010 126.600 1000A15481320071003 0
00001 2155010 126.600 4000A15475220071003 0
00001 2155010 126.600 5000A15593420071003 0