4
我經常使用d_ply來製作探險性地塊。將dplyr用於探索性地塊
一個小示例:
require(plyr)
plot_species <- function(species_data){
p <- qplot(data=species_data,
x=Sepal.Length,
y=Sepal.Width)
print(p)
}
d_ply(.data=iris,
.variables="Species",
function(x)plot_species(x))
哪產生三個獨立的曲線,每個物種。
我想使用dplyr中的函數重現此行爲。
這似乎要求重新彙總sumreze所調用的函數中的data.frame,這通常是不切實際的。
require(dplyr)
iris_by_species <- group_by(iris,Species)
plot_species <- function(Sepal.Length,Sepal.Width){
species_data <- data.frame(Sepal.Length,Sepal.Width)
p <- qplot(data=species_data,
x=Sepal.Length,
y=Sepal.Width)
print(p)
}
summarise(iris_by_species, plot_species(Sepal.Length,Sepal.Width))
能否data.frame的部分傳遞到通過總結直接調用,而不是傳遞列的功能?