那么的投入,我有一个函数:输出应该是另一个功能
complete <- function(directory,id = 1:332) {
directory <- list.files(path="......a")
g <- list()
for(i in 1:length(directory)) {
g[[i]] <- read.csv(directory[i],header=TRUE)
}
rbg <- do.call(rbind,g)
rbgr <- na.omit(rbg) #reads files and omits NA's
complete_subset <- subset(rbgr,rbgr$ID %in% id,select = ID)
table.rbgr <- sapply(complete_subset,table)
table.rbd <- data.frame(table.rbgr)
id.table <- c(id)
findla.tb <- cbind (id.table,table.rbd)
names(findla.tb) <- c("id","nob")
print(findla.tb) #creates table with number of observations
}
基本上当你调用特定的数字小ID(如4), 你想获得这个输出
id nobs
15 328
所以,我只需要NOBS数据被送入如果NOBS值比另一个任意确定的值(T)大,其测量两列之间的相关性的另一功能。由于nobs是由id的值决定的,我不确定如何创建一个考虑其他函数的输出的函数?
我已经试过这样的事情:
corr <- function (directory, t) {
directory <- list.files(path=".......")
g <- list()
for(i in 1:length(directory)) {
g[[i]] <- read.csv(directory[i],header=TRUE)
}
rbg <- do.call(rbind,g)
g.all <- na.omit(rbg) #reads files and removes observations
source(".....complete.R") #sourcing the complete function above
complete("spec",id)
g.allse <- subset(g.all,g.all$ID %in% id,scol)
g.allnit <- subset(g.all,g.all$ID %in% id,nit)
for(g.all$ID %in% id) {
if(id > t) {
cor(g.allse,g.allnit) #calcualte correlation of these two columns if they have similar id
}
}
#basically for each id that matches the ID in g.all function, if the id > t variable, calculate the correlation between columns
}
complete("spec", 3)
cr <- corr("spec", 150)
head(cr)
我也试图使完整功能的data.frame,但它不工作,它给了我下面的错误:在data.frame 错误(... check.names = false)参数意味着不同的行数。所以,我不知道如何继续......