complete <-function(directory,id){
#path<-directory
mymatrix <- matrix()
rowc<-1
# mylist <- list()
for(i in id){
fileStr <- paste(directory, "/", sprintf("%03d", as.numeric(i)), ".csv",
sep = "")
#filename<-paste(i,".csv",sep="")
#mydata<- read.csv((file=file.path(path, filename)), header=TRUE)
mydata<-read.csv(fileStr)
#cleandframe<- mydata[complete.cases(mydata),]
numCOmpleteCases<- sum(complete.cases(mydata))
#mymatrix(i,numCOmpleteCases)
# mylist[[rowc]]<- cbind(c(i,numCOmpleteCases))
mymatrix[rowc,] <-c(i,numCOmpleteCases)
rowc<- rowc+1
dframeComplete<-data.frame(id=i,nobs=numCOmpleteCases)
}
#dframeComplete<- (data.frame(id=id, nobs=sapply(id,numCompleteCases)))
#dframeComplete
mymatrix<-as.data.frame(mymatrix)
mymatrix
}
我正在尝试使用两列(id和numCompleteCases)来创建一个数据帧,我已尝试使用列表和矩阵,使用列表我得到的数据帧的列数相当于(id,numCompleteCases对) )而不是具有2列和与传递的对等效的行数的数据帧。