我正在使用以下代码从文件中提取完整案例的数量:
complete <- function(directory, id=1:332) {
sapply(id, fn, directory)}
fn <- function(id, directory) {
zero <- sprintf("%03d", id)
name <- paste(directory,"/",zero,".csv",sep="")
frame <- read.csv(name)
ok <- complete.cases(frame)
return(c("nobs"=sum(ok),"id"=id)) }
然后,例如:
complete("specdata",1:12)
此代码返回:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
nobs 117 1041 243 474 402 228 442 192 275 148 443 96
id 1 2 3 4 5 6 7 8 9 10 11 12
但是,我希望它返回以下类型的数据框:
我不确定我做错了什么。谢谢!