더 Beasterfield의 대답에 추가하려면, 그것은 보인다.
apply 명령문 내에서 복잡한 기능을 사용할 수 있습니다. 그래서 당신은 지금이 여기서
# 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) {
# 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
}
는 이것은로 번역 할 수 있습니다 :
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'를 읽으십시오), 또는 하나의 그래프 페이지 ('? par'를 읽습니다)에 여러 개의 그림을 넣을 수 있습니다. – Roland
롤업에 대해서는 for 루프가 괜찮다는 것에 동의하지만,이 예제의 data.frame 목록은 lapply에 적합합니다. –
@arumbay'ggplot2' 패키지에서 패싯 (facet) 그룹을 만들기 위해 패싯 (facetting)을 체크 아웃합니다. –