希望这会有所帮助。代表不足以在评论中询问信息,所以我会加入一些东西。我不知道您加载的对象是什么类(或其中的列),但您可以尝试确保它是一个数据框,然后使用子集:
#create some random nonsense
set.seed(123)
junk1 = data.frame(matrix(rnorm(100,5,.5),ncol=1,nrow=100))
junk2 = data.frame(matrix(1:100,ncol=100,nrow=100))
colnames(junk1)="Y"
test=cbind(junk1,junk2)
#should at this point have a data.frame something like your data, first column Y, rest X1..X100
#if yours isn't already, after doing your "test=read.csv(file)" then "test=as.data.frame(test)"
x_test = subset(test,select=colnames(test)[colnames(test)!="Y"])
y_test = subset(test,select="Y")
使用子集可能不是最好的方法,但它的优点是即使提取单个列(如您的“Y”),结果也将是一个数据框,而不是一个向量。
编辑:我刚刚看到的 Sven 的道具询问了课程(在发布之前没有看到)