从data.frame列表中排除向量

从data.frame列表中排除向量,r,R,我有一个50个data.frame对象的列表,每个data.frame对象包含20行。我需要在每次迭代时从data.frame对象中排除一行或一个向量 单个迭代可能如下所示: to_exclude <- 0 # 0 will be replaced by the induction variable training_temp <- lapply(training_data, function(x) {

我有一个50个data.frame对象的列表,每个data.frame对象包含20行。我需要在每次迭代时从data.frame对象中排除一行或一个向量

单个迭代可能如下所示:

to_exclude <- 0  # 0 will be replaced by the induction variable
training_temp <- lapply(training_data, function(x) {
                                        # Exclude the vector numbered to_exclude
                                        }
排除
因此,根据循环值:

remove_this_one <- 10
lapply(thelist, function(x) x[ -c(remove_this_one) ,] )
# remove row 10

remove\u这个\u你想从列表中的每个data.frame中删除同一行吗?类似于:
lappy(training\u data,function(x)x[-to\u exclude,])
但是我不知道我是否完全理解你的问题……如果training\u data是一个data.frame列表,那么你添加x@NathanG是的,它将是每个data.frame对象中的同一行。在这种情况下,要删除的行将由循环或排除对象决定。谢谢。您是否可以稍微更新代码,以使上述过程在循环中表示,并且在每次迭代中,我们从循环变量表示的每个data.frame对象中删除一行。@Shahzad此
lappy
技术是R中“循环”的首选方法。x[-remove,]列表的语法应该相当直接。如果不是的话,我建议你在网上看看任何一本优秀的指南。特别是子集和列表访问。
lapply(thelist, function(x) x[, -c(1) ] )

# because there are only two columns in this example you would probably 
# want to add drop = FALSe e.g.
# lapply(thelist, function(x) x[, -c(1), drop=FALSE ] )
remove_this_one <- 10
lapply(thelist, function(x) x[ -c(remove_this_one) ,] )
# remove row 10