0

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
                                        }

よろしく

4

1 に答える 1

0
df <- data.frame(x=1:10,y=1:10)

thelist <- list(df,df,df,df)

lapply(thelist, function(x) x[-c(1) ,] )

これにより、常に最初の行が削除されます。これはあなたが望むもののようですか、それとも値に基づいて行を削除したいですか?

これにより、常に最初の列が除外されます。

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
于 2013-01-31T23:37:45.050 に答える