我有一组调查数据,我想生成特定变量的地块,被申请人的国家分类。我写的代码迄今为止生成的情节是:获取的foreach()和GGPLOT2相处
countries <- isplit(drones, drones$v3)
foreach(country = countries) %dopar% {
png(file = paste(output.exp, "/Histogram of Job Satisfaction in ", country$key[[1]], ".png", sep = ""))
country.df <- data.frame(country) #ggplot2 doesn't appreciate the lists nextElem() produces
ggplot(country.df, aes(x = value.v51)) + geom_histogram()
dev.off()
}
真的很奇怪吗?我可以运行isplit(),设置country <- nextElem(countries)
,然后在不发送foreach行的情况下运行代码 - 并获得可爱的情节。如果我发送foreach,我会得到一些空白的.png文件。
在此先感谢您的帮助。
我可以肯定地与标准的R做循环,但我真的很想得到foreach
一个更好的把握。
你能发布一些示例数据?这会让测试变得更容易。 –
当然。诚实善良的数据:http://drop.io/cy81s4w/asset/sample-data-rdata –
我希望使用实际的数据是好的 - 有点不寻常,但它似乎是最有效的。只需使用load(file.choose())将该数据输入到R中,然后使用无人机< - 样本。你还需要将output.exp设置为你想要显示19个.png文件的文件夹。 –