-2

我有 102 个文本文件,每个文件都包含相同类型的数据。假设数据存储在文件 f1 的变量 d1 中。

在 R 中:我想在两个文件中的数据之间进行绘图。说 d1 vs d2 或 d45 vs d85

我需要为所有组合( 102C2 组合)做这些

我怎么做?

4

1 回答 1

2

这有点像外面的要求,因为你无法理解这么多的情节。例如:

ncol(combn(1:102,2))

为 102 组数据之间的唯一组合提供总共5151个图。如果你的教授想手动搜索所有这些图,他最好给自己倒一大杯咖啡。我会认真重新考虑您试图从这些数据中找出什么,并可能重新定义您的调查范围。

话虽如此,考虑到具体情况,这里有一些潜在的代码可能是好的建议,也可能不是好的建议。事实上,我什至建议不要对所有文件运行以下代码,以免计算机爆炸。

# This is how you would read text files into a list,
# courtesy of this question (http://stackoverflow.com/q/9110110/496803):
# raw <- list.files(pattern="*.txt")
# listy <- lapply(raw, read.table)

# set up some mock data instead
listy <- list(1:3,4:6,7:9)

# get every possible combination
combos <- combn(1:length(listy),2)

# define a function to plot each combination of data  
multiplot <- function(x) {
    dev.new()
    plot(listy[[(x[1])]],listy[[x[2]]])
}

# Generate the plots separately.
# This will probably kill your R session with
# the number of plots you are generating.

apply(combos,2,multiplot)
于 2012-05-21T03:09:17.497 回答