R 我不知道如何把函数列表的每一个结果都拿出来

R 我不知道如何把函数列表的每一个结果都拿出来,r,R,RStudio版本1.0.143 Windows版本:Windows10 Pro 我有300多个具有相同结构的文件,我想创建一个循环,这样它可以计算所需文件的相关索引。我可以得到正确的文件并计算相关指数,但我不能得到所有显示的结果。我试图将它们保存到向量中,但它告诉我找不到对象。如果它能工作,我还担心如果我运行函数几次,向量的内容是否会保留下来。以下是循环: 因为在印度{ +specdata_i在使用ou[i]访问变量ou之前,必须先创建变量ou: > setwd("C:/Users/su

RStudio版本1.0.143

Windows版本:Windows10 Pro

我有300多个具有相同结构的文件,我想创建一个循环,这样它可以计算所需文件的相关索引。我可以得到正确的文件并计算相关指数,但我不能得到所有显示的结果。我试图将它们保存到向量中,但它告诉我找不到对象。如果它能工作,我还担心如果我运行函数几次,向量的内容是否会保留下来。以下是循环:

因为在印度{
+specdata_i在使用ou[i]访问变量ou之前,必须先创建变量ou:

> setwd("C:/Users/sunxi/Coursera/specdata")
> ind <- dir(path = "C:/Users/sunxi/Coursera/specdata", pattern = ".csv") #Save the index of the files to a vector.
> specdata_ful <- lapply(ind, read.csv) #combine all the files to a data frame.
> specdat_recon_ful <- do.call(rbind, specdata_ful) #Reconstruct the data frame to put the same variable in one column.
> com_case_ful <- complete.cases(specdat_recon_ful) #Filter the complete cases.
> id_ful <- specdat_recon_ful[,4][com_case_ful] #The ID of the complete cases.
> sulfate_ful <- specdat_recon_ful[,2][com_case_ful] #The sulfate value of the complete cases.
> nitrate_ful <- specdat_recon_ful[,3][com_case_ful] #The nitrate value of the complete cases.
> id_freq_ful <- table(id_ful) #Summary the frequency in each id
> id_freq_mat_ful <- as.data.frame(id_freq_ful) #transfer the table into the data.frame.
> good <- id_freq_mat_ful[["Freq"]] > 1000 #Filter the freqency larger than threshold.
> id_good <- id_freq_mat_ful[["id_ful"]][good] #Filter the id has the frequency of complete cases larger than the threshold.
> ind_larg <- ind[id_good] #Create an index for the id has required requency.
ou <- c()
for(i in ind_larg){
    # your loop here...
    ou[i] <- cor(sulfate_i, nitrate_i)
}