あなたがデータフレームのそれぞれに複雑な操作をいくつかやりたいように、それはそうです。
適用ステートメント内で複雑な機能を使用することは可能です。だから、あなたが今持っている場所:
lapply(dflist, function(df) {
# Do some complex operations on each data frame, df
# More steps
# Make sure the last thing is NULL. The last statement within the function will be
# returned to lapply, which will try to combine these as a list across all data frames.
# You don't actually care about this, you just want to run the function.
NULL
})
プロットを使用して、より具体的な例:
for (i in dflist) {
# Do some complex things
}
これは、に変換することができ
# Assuming we have a data frame with our points on the x, and y axes,
lapply(dflist, function(df) {
x2 <- df$x^2
log_y <- log(df$y)
plot(x,y)
NULL
})
また、複数の引数を取る複雑な関数を書くことができます:
lapply(dflist, function(df, arg1, arg2) {
# Do something on each data.frame, df
# arg1 == 1, arg2 == 2 (see next line)
}, 1, 2) # extra arguments are passed in here
これがあなたを助けてくれることを願っています!
'for'ループを使用して結構です。実際のdata.framesをベクトルの名前だけでなくリストに入れてください。読みやすくするために、ループの内容を 'plot(var2〜var1、data = i)'に変更することもできます。しかし、プロットを保存する( '?pdf'を読む)か、複数のプロットを1つのグラフページ('?par'を読んでください)に入れたいかもしれません。 – Roland
私はRolandに賛成ですが、forループのほうがうまくいきますが、この例ではdata.frameのリストはlapplyにはうってつけです。 –
@arumbay 'ggplot2'パッケージのファセットをチェックして、プロットのグループを作成します。 –