我想在for循环中使用多组文件

时间:2019-05-21 02:08:11

标签: r rscript

我有3个训练集文件和3个测试集文件。我想将 testset1 trainingset1 进行分类,将 testset2 trainingset2 进行分类,将 testset3 trainingset3

lapply用于在多个文件上应用功能。但是,我想处理两组文件。

#Imbalanced Training Set

trainset <- list.files(path= "D:/Datasets/yeast-1-2-8-9_vs_7-5-fold/", pattern="tra.csv")
trainset
#trainset=read.csv("D:/Datasets/yeast-1-2-8-9_vs_7-5-fold/yeast-1-2-8-9_vs_7-5-2tra.csv")
#table(trainset$Class)

# Test Set Input
testset <- list.files(path= "D:/Datasets/yeast-1-2-8-9_vs_7-5-fold/", pattern="tst.csv")
testset
#testset=read.csv("D:/Datasets/yeast-1-2-8-9_vs_7-5-fold/yeast-1-2-8-9_vs_7-5-2tst.csv")
#table(testset$Class)

loopvariable=length(testset)
loopvariable

# Imbalance training set classifying test set results
for ( j in 1:loopvariable)

{

rftrainfirst<-randomForest(Class~., data=trainset[j])

rftrainfirst

rftrainfirst<-randomForest(Class~., data=trainset[j]).  Here it is showing the following error. 
  

terms.formula(formula,data = data)中的错误:“。”在公式和   没有“数据”参数

0 个答案:

没有答案